From 1b800cdf612d4ec6e916e959a95604c91f0ba7e9 Mon Sep 17 00:00:00 2001 From: Edward Surov Date: Fri, 10 Nov 2023 17:32:58 +0200 Subject: [PATCH] test method is correctly detectied with data provider (fixes #98, via #99) --- .github/workflows/build.yml | 12 +++++-- composer.json | 23 ++++++++++++ phpunit.10.0.report.xml | 25 +++++++++++++ phpunit.10.0.xml | 23 ++++++++++++ phpunit.report.xml | 8 ++++- phpunit.xml.dist | 17 ++++++--- src/Internal/TestLifecycle.php | 26 +++++++++----- test/report/Generate/DataProviderTest.php | 44 +++++++++++++++++++++++ test/report/Generate/NegativeTest.php | 22 ++++-------- test/unit/Event/EventTestTrait.php | 1 + 10 files changed, 170 insertions(+), 31 deletions(-) create mode 100644 phpunit.10.0.report.xml create mode 100644 phpunit.10.0.xml create mode 100644 test/report/Generate/DataProviderTest.php diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ecd4d9f..539bf73 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -49,9 +49,17 @@ jobs: ${{ matrix.composer-options }} - name: Run tests - if: ${{ matrix.os != 'windows-latest' }} + if: ${{ matrix.os != 'windows-latest' && !contains(matrix.composer-options, '--prefer-lowest') }} run: composer test + - name: Run tests (lowest) + if: ${{ matrix.os != 'windows-latest' && contains(matrix.composer-options, '--prefer-lowest') }} + run: composer test-lowest + - name: Run tests (windows) - if: ${{ matrix.os == 'windows-latest' }} + if: ${{ matrix.os == 'windows-latest' && !contains(matrix.composer-options, '--prefer-lowest') }} run: composer test-windows + + - name: Run tests (windows-lowest) + if: ${{ matrix.os == 'windows-latest' && contains(matrix.composer-options, '--prefer-lowest') }} + run: composer test-windows-lowest diff --git a/composer.json b/composer.json index 83054a0..4068c41 100644 --- a/composer.json +++ b/composer.json @@ -60,17 +60,28 @@ "scripts": { "test-cs": "vendor/bin/phpcs -sp", "test-unit": "vendor/bin/phpunit --coverage-text", + "test-unit-lowest": "vendor/bin/phpunit --configuration=phpunit.10.0.xml --coverage-text", "clear-allure-results": "rm -rf ./build/allure-results", "test-report": [ "@clear-allure-results", "vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=positive", "vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=negative; exit 0" ], + "test-report-lowest": [ + "@clear-allure-results", + "vendor/bin/paratest --processes=3 --configuration=phpunit.10.0.report.xml --testsuite=positive", + "vendor/bin/paratest --processes=3 --configuration=phpunit.10.0.report.xml --testsuite=negative; exit 0" + ], "test-report-windows": [ "@clear-allure-results", "vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=positive", "vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=negative & exit 0" ], + "test-report-windows-lowest": [ + "@clear-allure-results", + "vendor/bin/paratest --processes=3 --configuration=phpunit.10.0.report.xml --testsuite=positive", + "vendor/bin/paratest --processes=3 --configuration=phpunit.10.0.report.xml --testsuite=negative & exit 0" + ], "test-psalm": "vendor/bin/psalm --shepherd", "test": [ "@test-cs", @@ -78,11 +89,23 @@ "@test-report", "@test-psalm" ], + "test-lowest": [ + "@test-cs", + "@test-unit-lowest", + "@test-report-lowest", + "@test-psalm" + ], "test-windows": [ "@test-cs", "@test-unit", "@test-report-windows", "@test-psalm" + ], + "test-windows-lowest": [ + "@test-cs", + "@test-unit-lowest", + "@test-report-windows-lowest", + "@test-psalm" ] } } diff --git a/phpunit.10.0.report.xml b/phpunit.10.0.report.xml new file mode 100644 index 0000000..1531268 --- /dev/null +++ b/phpunit.10.0.report.xml @@ -0,0 +1,25 @@ + + + + + test/report/Generate + test/report/Generate/NegativeTest.php + + + test/report/Generate/NegativeTest.php + + + + + + diff --git a/phpunit.10.0.xml b/phpunit.10.0.xml new file mode 100644 index 0000000..843e6c0 --- /dev/null +++ b/phpunit.10.0.xml @@ -0,0 +1,23 @@ + + + + + test/unit/ + + + + + src/ + + + diff --git a/phpunit.report.xml b/phpunit.report.xml index 60298d5..3f527f7 100644 --- a/phpunit.report.xml +++ b/phpunit.report.xml @@ -1,8 +1,14 @@ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f7ce70a..61a0901 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,17 +1,26 @@ test/unit/ - + - src/ + src/ - + + vendor/ + + diff --git a/src/Internal/TestLifecycle.php b/src/Internal/TestLifecycle.php index 0053700..28935dc 100644 --- a/src/Internal/TestLifecycle.php +++ b/src/Internal/TestLifecycle.php @@ -165,18 +165,26 @@ private function getCurrentTest(): TestInfo private function buildTestInfo(string $test, ?string $host = null, ?string $thread = null): TestInfo { - $dataLabelMatchResult = preg_match( - '#^([^\s]+)\s+with\s+data\s+set\s+(\#\d+|".+")\s+\(.+\)$#', + /** @var list $matches */ + $classAndMethodMatchResult = preg_match( + '#^(\S+)(.*)$#', $test, $matches, ); - - /** @var list $matches */ - if (1 === $dataLabelMatchResult) { - $classAndMethod = $matches[1] ?? null; - $dataLabel = $matches[2] ?? '?'; - } else { - $classAndMethod = $test; + [$classAndMethod, $dataSetInfo] = 1 === $classAndMethodMatchResult + ? [$matches[1] ?? null, $matches[2] ?? null] + : [$test, null]; + $dataLabelMatchResult = isset($dataSetInfo) + ? preg_match( + '/^\s+with\s+data\s+set\s+(?:(#\d+)|"(.*)")$/', + $dataSetInfo, + $matches, + ) + : false; + $dataLabel = 1 === $dataLabelMatchResult + ? $matches[2] ?? $matches[1] ?? null + : null; + if ('' === $dataLabel) { $dataLabel = null; } diff --git a/test/report/Generate/DataProviderTest.php b/test/report/Generate/DataProviderTest.php new file mode 100644 index 0000000..ec21540 --- /dev/null +++ b/test/report/Generate/DataProviderTest.php @@ -0,0 +1,44 @@ + self::assertSame($x, $y)); + } + + public static function providerNamed(): iterable + { + return [ + 'Simple name' => [1, 1], + '' => [2, 2], + '"Double-quoted" name' => [3, 3], + "'Single-quoted' name" => [4, 4], + ' ' => [5, 5], + ]; + } + + #[DataProvider('providerListed')] + public function testListedDataSet(int $x, int $y): void + { + Allure::runStep(fn () => self::assertSame($x, $y)); + } + + public static function providerListed(): iterable + { + return [ + [1, 1], + [2, 2], + ]; + } +} diff --git a/test/report/Generate/NegativeTest.php b/test/report/Generate/NegativeTest.php index fe68a69..c12aee9 100644 --- a/test/report/Generate/NegativeTest.php +++ b/test/report/Generate/NegativeTest.php @@ -4,13 +4,17 @@ namespace Qameta\Allure\PHPUnit\Test\Report\Generate; -use PHPUnit\Event; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\TestCase; use Qameta\Allure\Allure; use Qameta\Allure\Attribute\DisplayName; use Qameta\Allure\PHPUnit\ExceptionDetailsTrait; use RuntimeException; +use function trigger_error; + +use const E_USER_WARNING; + class NegativeTest extends TestCase { use ExceptionDetailsTrait; @@ -51,22 +55,10 @@ function () { ); } - #[DisplayName('Test that emits warning is reported as broken')] + #[DisplayName('Test that emits warning is reported as broken'), DoesNotPerformAssertions] public function testWarning(): void { - /** - * @psalm-suppress InternalMethod - * @psalm-suppress InternalClass - * @psalm-suppress TooManyArguments - */ - Event\Facade::emitter()->testTriggeredWarning( - $this->valueObjectForEvents(), - "Test triggered warning", - __FILE__, - __LINE__, - false, - ); - self::assertTrue(true); + trigger_error('"Test triggered warning"', E_USER_WARNING); } #[DisplayName('Skipped test is reported as skipped')] diff --git a/test/unit/Event/EventTestTrait.php b/test/unit/Event/EventTestTrait.php index e1bc2a0..0c1bd65 100644 --- a/test/unit/Event/EventTestTrait.php +++ b/test/unit/Event/EventTestTrait.php @@ -261,6 +261,7 @@ protected function createTestWarningTriggeredEvent( 'file', 1, false, + false, ); } }