|
18 | 18 | use PHPUnit\Framework\TestSuite;
|
19 | 19 | use PHPUnit\Runner\ResultCache\DefaultResultCache;
|
20 | 20 | use PHPUnit\Runner\ResultCache\ResultCacheId;
|
| 21 | +use PHPUnit\TestFixture\FaillingDataProviderTest; |
21 | 22 | use PHPUnit\TestFixture\MultiDependencyTest;
|
22 | 23 | use ReflectionClass;
|
23 | 24 |
|
@@ -436,6 +437,74 @@ public static function suiteSorterOptionPermutationsProvider(): array
|
436 | 437 | return $data;
|
437 | 438 | }
|
438 | 439 |
|
| 440 | + /** |
| 441 | + * A data provider for testing defects execution reordering options based on FaillingDataProviderTest. |
| 442 | + */ |
| 443 | + public static function defectsSorterWithDataProviderProvider(): array |
| 444 | + { |
| 445 | + return [ |
| 446 | + // The most simple situation should work as normal |
| 447 | + 'default, no defects' => [ |
| 448 | + TestSuiteSorter::ORDER_DEFAULT, |
| 449 | + self::IGNORE_DEPENDENCIES, |
| 450 | + [ |
| 451 | + 'testOne' => ['state' => TestStatus::success(), 'time' => 1], |
| 452 | + 'testWithProvider with data set "good1"' => ['state' => TestStatus::success(), 'time' => 1], |
| 453 | + 'testWithProvider with data set "good2"' => ['state' => TestStatus::success(), 'time' => 1], |
| 454 | + 'testWithProvider with data set "good3"' => ['state' => TestStatus::success(), 'time' => 1], |
| 455 | + 'testWithProvider with data set "fail1"' => ['state' => TestStatus::success(), 'time' => 1], |
| 456 | + 'testWithProvider with data set "fail2"' => ['state' => TestStatus::success(), 'time' => 1], |
| 457 | + ], |
| 458 | + [ |
| 459 | + FaillingDataProviderTest::class . '::testWithProvider with data set "good1"', |
| 460 | + FaillingDataProviderTest::class . '::testWithProvider with data set "good2"', |
| 461 | + FaillingDataProviderTest::class . '::testWithProvider with data set "fail1"', |
| 462 | + FaillingDataProviderTest::class . '::testWithProvider with data set "good3"', |
| 463 | + FaillingDataProviderTest::class . '::testWithProvider with data set "fail2"', |
| 464 | + FaillingDataProviderTest::class . '::testOne', |
| 465 | + ], |
| 466 | + ], |
| 467 | + |
| 468 | + // Running with an empty cache should not spook the TestSuiteSorter |
| 469 | + 'default, empty result cache' => [ |
| 470 | + TestSuiteSorter::ORDER_DEFAULT, |
| 471 | + self::IGNORE_DEPENDENCIES, |
| 472 | + [ |
| 473 | + // empty result cache |
| 474 | + ], |
| 475 | + [ |
| 476 | + FaillingDataProviderTest::class . '::testWithProvider with data set "good1"', |
| 477 | + FaillingDataProviderTest::class . '::testWithProvider with data set "good2"', |
| 478 | + FaillingDataProviderTest::class . '::testWithProvider with data set "fail1"', |
| 479 | + FaillingDataProviderTest::class . '::testWithProvider with data set "good3"', |
| 480 | + FaillingDataProviderTest::class . '::testWithProvider with data set "fail2"', |
| 481 | + FaillingDataProviderTest::class . '::testOne', |
| 482 | + ], |
| 483 | + ], |
| 484 | + |
| 485 | + 'default, defects' => [ |
| 486 | + TestSuiteSorter::ORDER_DEFAULT, |
| 487 | + self::IGNORE_DEPENDENCIES, |
| 488 | + [ |
| 489 | + 'testOne' => ['state' => TestStatus::success(), 'time' => 1], |
| 490 | + 'testWithProvider with data set "good1"' => ['state' => TestStatus::success(), 'time' => 1], |
| 491 | + 'testWithProvider with data set "good2"' => ['state' => TestStatus::success(), 'time' => 1], |
| 492 | + 'testWithProvider with data set "good3"' => ['state' => TestStatus::success(), 'time' => 1], |
| 493 | + 'testWithProvider with data set "fail1"' => ['state' => TestStatus::error(), 'time' => 1], |
| 494 | + 'testWithProvider with data set "fail2"' => ['state' => TestStatus::error(), 'time' => 1], |
| 495 | + ], |
| 496 | + [ |
| 497 | + FaillingDataProviderTest::class . '::testWithProvider with data set "fail1"', |
| 498 | + FaillingDataProviderTest::class . '::testWithProvider with data set "fail2"', |
| 499 | + FaillingDataProviderTest::class . '::testWithProvider with data set "good1"', |
| 500 | + FaillingDataProviderTest::class . '::testWithProvider with data set "good2"', |
| 501 | + FaillingDataProviderTest::class . '::testWithProvider with data set "good3"', |
| 502 | + FaillingDataProviderTest::class . '::testOne', |
| 503 | + ], |
| 504 | + ], |
| 505 | + ]; |
| 506 | + } |
| 507 | + |
439 | 508 | public function testThrowsExceptionWhenUsingInvalidOrderOption(): void
|
440 | 509 | {
|
441 | 510 | $suite = TestSuite::empty('test suite name');
|
@@ -622,4 +691,23 @@ public function testSuiteSorterDefectsOptions(int $order, bool $resolveDependenc
|
622 | 691 |
|
623 | 692 | $this->assertSame($expected, $sorter->getExecutionOrder());
|
624 | 693 | }
|
| 694 | + |
| 695 | + #[DataProvider('defectsSorterWithDataProviderProvider')] |
| 696 | + public function testSuiteSorterDefectsWithDataProviderTest(int $order, bool $resolveDependencies, array $runState, array $expected): void |
| 697 | + { |
| 698 | + $suite = TestSuite::empty('test suite name'); |
| 699 | + $suite->addTestSuite(new ReflectionClass(FaillingDataProviderTest::class)); |
| 700 | + |
| 701 | + $cache = new DefaultResultCache; |
| 702 | + |
| 703 | + foreach ($runState as $testName => $data) { |
| 704 | + $cache->setStatus(ResultCacheId::fromTestClassAndMethodName(FaillingDataProviderTest::class, $testName), $data['state']); |
| 705 | + $cache->setTime(ResultCacheId::fromTestClassAndMethodName(FaillingDataProviderTest::class, $testName), $data['time']); |
| 706 | + } |
| 707 | + |
| 708 | + $sorter = new TestSuiteSorter($cache); |
| 709 | + $sorter->reorderTestsInSuite($suite, $order, $resolveDependencies, TestSuiteSorter::ORDER_DEFECTS_FIRST); |
| 710 | + |
| 711 | + $this->assertSame($expected, $sorter->getExecutionOrder()); |
| 712 | + } |
625 | 713 | }
|
0 commit comments