Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Forward the spec title as the dataprovider label #1005

Merged
merged 3 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/Scoper/PhpScoperSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public static function provideValidFiles(): iterable
foreach ($files as $file) {
$scenarios = SpecParser::parseSpecFile($sourceDir, $file);

foreach ($scenarios as $scenario) {
yield [$scenario];
foreach ($scenarios as $label => $scenario) {
yield $label => [$scenario];
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions tests/SpecFramework/SpecParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SpecParser extends TestCase
/**
* @throws UnparsableFile
*
* @return iterable<SpecScenario>
* @return iterable<string, SpecScenario>
*/
public static function parseSpecFile(
string $sourceDir,
Expand All @@ -57,8 +57,10 @@ public static function parseSpecFile(
unset($specs['meta']);

foreach ($specs as $title => $spec) {
yield self::parseSpec(
basename($sourceDir).'/'.$file->getRelativePathname(),
$relativePath = basename($sourceDir).'/'.$file->getRelativePathname();

yield $relativePath.': '.$title => self::parseSpec(
$relativePath,
$meta,
$title,
$spec,
Expand Down
10 changes: 5 additions & 5 deletions tests/SpecFrameworkTest/SpecParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static function specProvider(): iterable
yield 'simple spec' => [
self::FIXTURE_DIR.'/simple-spec-file.php',
[
new SpecScenario(
'Fixtures/simple-spec-file.php: 0' => new SpecScenario(
null,
null,
'Fixtures/simple-spec-file.php',
Expand All @@ -83,7 +83,7 @@ public static function specProvider(): iterable
[],
[],
),
new SpecScenario(
'Fixtures/simple-spec-file.php: A spec with a title' => new SpecScenario(
null,
null,
'Fixtures/simple-spec-file.php',
Expand All @@ -105,7 +105,7 @@ public static function specProvider(): iterable
yield 'complete spec' => [
self::FIXTURE_DIR.'/complete-spec-file.php',
[
new SpecScenario(
'Fixtures/complete-spec-file.php: Spec with default meta values' => new SpecScenario(
72_000,
83_000,
'Fixtures/complete-spec-file.php',
Expand All @@ -129,7 +129,7 @@ public static function specProvider(): iterable
['Acme\RecordedClass', 'Humbug\Acme\RecordedClass'],
['Acme\recorded_function', 'Humbug\Acme\recorded_function'],
),
new SpecScenario(
'Fixtures/complete-spec-file.php: Spec with the more verbose form' => new SpecScenario(
72_000,
83_000,
'Fixtures/complete-spec-file.php',
Expand All @@ -153,7 +153,7 @@ public static function specProvider(): iterable
['Acme\RecordedClass', 'Humbug\Acme\RecordedClass'],
['Acme\recorded_function', 'Humbug\Acme\recorded_function'],
),
new SpecScenario(
'Fixtures/complete-spec-file.php: Spec with overridden meta values' => new SpecScenario(
73_000,
82_000,
'Fixtures/complete-spec-file.php',
Expand Down
Loading