Skip to content

Commit 7d226fa

Browse files
smuufdg
authored andcommitted
Add testcase method's name to the test's title. (#451)
Resolves #448.
1 parent 027bd0a commit 7d226fa

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/Runner/Test.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ public function getOutput(): string
100100
}
101101

102102

103+
public function withTitle(string $title): self
104+
{
105+
if ($this->hasResult()) {
106+
throw new \LogicException('Cannot change title to test which already has a result.');
107+
}
108+
109+
$me = clone $this;
110+
$me->title = $title;
111+
return $me;
112+
}
113+
114+
103115
/**
104116
* @return static
105117
*/

src/Runner/TestHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ private function initiateTestCase(Test $test, $foo, PhpInterpreter $interpreter)
228228
}
229229

230230
return array_map(
231-
fn(string $method): Test => $test->withArguments(['method' => $method]),
231+
fn(string $method): Test => $test
232+
->withTitle("$test->title $method")
233+
->withArguments(['method' => $method]),
232234
$methods,
233235
);
234236
}

tests/Runner/Job.phpt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require __DIR__ . '/../../src/Runner/Test.php';
1010
require __DIR__ . '/../bootstrap.php';
1111

1212

13-
test('', function () {
13+
test('appending arguments to Test', function () {
1414
$test = (new Test('Job.test.phptx'))->withArguments(['one', 'two' => 1])->withArguments(['three', 'two' => 2]);
1515
$job = new Job($test, createInterpreter());
1616
$job->setTempDirectory(Tester\Helpers::prepareTempDir(sys_get_temp_dir()));
@@ -28,3 +28,13 @@ test('', function () {
2828
Assert::contains('Nette Tester', $job->getHeaders());
2929
}
3030
});
31+
32+
33+
test('appending title to a Test', function () {
34+
$testA = (new Test('Job.test.phptx'));
35+
Assert::null($testA->title);
36+
37+
$testB = $testA->withTitle('title');
38+
Assert::notSame($testB, $testA);
39+
Assert::same('title', $testB->title);
40+
});

0 commit comments

Comments
 (0)