Skip to content

Commit

Permalink
Add testcase method's name to the test's title. (#451)
Browse files Browse the repository at this point in the history
Resolves #448.
  • Loading branch information
smuuf authored and dg committed Jun 18, 2024
1 parent 9fd36f8 commit ce52092
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Framework/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function findCommonDirectory(array $paths): string


/**
* Parse phpDoc comment.
* Parse the first docblock encountered in the provided string.
* @internal
*/
public static function parseDocComment(string $s): array
Expand Down
12 changes: 12 additions & 0 deletions src/Runner/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ public function getOutput(): string
}


public function withTitle(string $title): self
{
if ($this->hasResult()) {
throw new \LogicException('Cannot change title to test which already has a result.');
}

$me = clone $this;
$me->title = $title;
return $me;
}


/**
* @return static
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Runner/TestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ private function initiateTestCase(Test $test, $foo, PhpInterpreter $interpreter)
}

return array_map(
fn(string $method): Test => $test->withArguments(['method' => $method]),
fn(string $method): Test => $test
->withTitle("$test->title $method")
->withArguments(['method' => $method]),
$methods,
);
}
Expand Down
12 changes: 11 additions & 1 deletion tests/Runner/Job.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require __DIR__ . '/../../src/Runner/Test.php';
require __DIR__ . '/../bootstrap.php';


test('', function () {
test('appending arguments to Test', function () {
$test = (new Test('Job.test.phptx'))->withArguments(['one', 'two' => 1])->withArguments(['three', 'two' => 2]);
$job = new Job($test, createInterpreter());
$job->setTempDirectory(Tester\Helpers::prepareTempDir(sys_get_temp_dir()));
Expand All @@ -28,3 +28,13 @@ test('', function () {
Assert::contains('Nette Tester', $job->getHeaders());
}
});


test('appending title to a Test', function () {
$testA = (new Test('Job.test.phptx'));
Assert::null($testA->title);

$testB = $testA->withTitle('title');
Assert::notSame($testB, $testA);
Assert::same('title', $testB->title);
});

0 comments on commit ce52092

Please sign in to comment.