From 95f41cc65ef4d5b5e19e36f3fd3af55b447ce646 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 9 Nov 2024 11:17:02 +0100 Subject: [PATCH] fix dumping tests to skip with data providers Without the fix running `SYMFONY_PHPUNIT_SKIPPED_TESTS='phpunit.skipped' php ./phpunit src/Symfony/Component/Lock/Tests/Store/DoctrineDbalPostgreSqlStoreTest.php` without the pdo_pgsql extension enabled the generated skip file looked like this: ``` array ( 'Symfony\\Component\\Lock\\Tests\\Store\\DoctrineDbalPostgreSqlStoreTest::testInvalidDriver' => 1, ), 'Symfony\\Component\\Lock\\Tests\\Store\\DoctrineDbalPostgreSqlStoreTest' => array ( 'testSaveAfterConflict' => 1, 'testWaitAndSaveAfterConflictReleasesLockFromInternalStore' => 1, 'testWaitAndSaveReadAfterConflictReleasesLockFromInternalStore' => 1, 'testSave' => 1, 'testSaveWithDifferentResources' => 1, 'testSaveWithDifferentKeysOnSameResources' => 1, 'testSaveTwice' => 1, 'testDeleteIsolated' => 1, 'testBlockingLocks' => 1, 'testSharedLockReadFirst' => 1, 'testSharedLockWriteFirst' => 1, 'testSharedLockPromote' => 1, 'testSharedLockPromoteAllowed' => 1, 'testSharedLockDemote' => 1, ), ); ``` Thus, running the tests again with the extension enabled would only run 14 tests instead of the expected total number of 16 tests. With the patch applied the generated skip file looks like this: ``` array ( 'testInvalidDriver with data set #0' => 1, 'testInvalidDriver with data set #1' => 1, 'testSaveAfterConflict' => 1, 'testWaitAndSaveAfterConflictReleasesLockFromInternalStore' => 1, 'testWaitAndSaveReadAfterConflictReleasesLockFromInternalStore' => 1, 'testSave' => 1, 'testSaveWithDifferentResources' => 1, 'testSaveWithDifferentKeysOnSameResources' => 1, 'testSaveTwice' => 1, 'testDeleteIsolated' => 1, 'testBlockingLocks' => 1, 'testSharedLockReadFirst' => 1, 'testSharedLockWriteFirst' => 1, 'testSharedLockPromote' => 1, 'testSharedLockPromoteAllowed' => 1, 'testSharedLockDemote' => 1, ), ); ``` --- .../Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php index a623edbbf15d..cadd6dddb280 100644 --- a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php +++ b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php @@ -13,6 +13,7 @@ use Doctrine\Common\Annotations\AnnotationRegistry; use PHPUnit\Framework\AssertionFailedError; +use PHPUnit\Framework\DataProviderTestSuite; use PHPUnit\Framework\RiskyTestError; use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestSuite; @@ -196,7 +197,13 @@ public function startTestSuite($suite) public function addSkippedTest($test, \Exception $e, $time) { if (0 < $this->state) { - $this->isSkipped[\get_class($test)][$test->getName()] = 1; + if ($test instanceof DataProviderTestSuite) { + foreach ($test->tests() as $testWithDataProvider) { + $this->isSkipped[\get_class($testWithDataProvider)][$testWithDataProvider->getName()] = 1; + } + } else { + $this->isSkipped[\get_class($test)][$test->getName()] = 1; + } } }