-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Bring back --repeat CLI option
#6397
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
Open
nikophil
wants to merge
21
commits into
sebastianbergmann:main
Choose a base branch
from
nikophil:feat/repeat-option
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,492
−83
Open
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
bb47770
Add basic phpt test with repeat option
nikophil 6b5f2b2
implement naive simple --repeat functionality
nikophil 6286d21
Repeat tests using RepeatTestSuite
nikophil 3ef7738
Handle dependent tests with --repeat
nikophil ec603b7
Handle data providers with --repeat
nikophil 1f5c46c
Repeat phpt tests
nikophil eb4829f
Handle test suite loaded from path with --repeat
nikophil e079b71
--repeat value should be a positive integer
nikophil 6a9fadd
cs fixer
nikophil c6ec4c0
add @internal tag on markSkippedForErrorInPreviousRepetition
nikophil 638b334
rename $repeat into $repeatTimes
nikophil ab52255
fix tests
nikophil 1773e58
add --repeat to the cli help
nikophil 32e3acb
handle when no cli arguments
nikophil a34f966
add test which uses #[RunTestsInSeparateProcesses]
nikophil 62ea645
Trigger test Passed event only when last repetition passed
nikophil 5cc4fae
Create RepeatTestSuite in TestBuilder
nikophil 20aa69c
Split regular RepeatTestSuite and PhptRepeatTestSuite
nikophil e9ff6a6
Add $repeatAttemptNumber property in test event DTOs
nikophil 539fb97
add repeat test with dependency ordered by random
nikophil ae0c716
Cannot retry if depends on test which returns value
nikophil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| <?php declare(strict_types=1); | ||
| /* | ||
| * This file is part of PHPUnit. | ||
| * | ||
| * (c) Sebastian Bergmann <[email protected]> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
| namespace PHPUnit\Framework; | ||
|
|
||
| use function count; | ||
| use LogicException; | ||
| use PHPUnit\Event; | ||
| use PHPUnit\Event\Facade as EventFacade; | ||
| use PHPUnit\Runner\Phpt\TestCase as PhptTestCase; | ||
| use PHPUnit\TestRunner\TestResult\PassedTests; | ||
|
|
||
| /** | ||
| * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit | ||
| * | ||
| * @internal This class is not covered by the backward compatibility promise for PHPUnit | ||
| */ | ||
| final readonly class RepeatTestSuite implements Reorderable, Test | ||
| { | ||
| /** | ||
| * @var non-empty-list<PhptTestCase>|non-empty-list<TestCase> | ||
| */ | ||
| private array $tests; | ||
|
|
||
| /** | ||
| * @param positive-int $times | ||
| */ | ||
| public function __construct(PhptTestCase|TestCase $test, int $times) | ||
| { | ||
| $tests = []; | ||
|
|
||
| for ($i = 0; $i < $times; $i++) { | ||
| $tests[] = $test; | ||
| } | ||
|
|
||
| $this->tests = $tests; | ||
| } | ||
|
|
||
| public function count(): int | ||
| { | ||
| return count($this->tests); | ||
| } | ||
|
|
||
| public function run(): void | ||
| { | ||
| if ($this->isPhptTestCase()) { | ||
| $this->runPhptTestCase(); | ||
| } else { | ||
| $this->runTestCase(); | ||
| } | ||
| } | ||
|
|
||
| public function sortId(): string | ||
| { | ||
| return $this->tests[0]->sortId(); | ||
| } | ||
|
|
||
| public function provides(): array | ||
| { | ||
| return $this->tests[0]->provides(); | ||
| } | ||
|
|
||
| public function requires(): array | ||
| { | ||
| return $this->tests[0]->requires(); | ||
| } | ||
|
|
||
| public function name(): string | ||
| { | ||
| if ($this->isPhptTestCase()) { | ||
| throw new LogicException('Cannot call RepeatTestSuite::nameWithDataSet() on a PhptTestCase.'); | ||
| } | ||
nikophil marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return $this->tests[0]::class . '::' . $this->tests[0]->nameWithDataSet(); | ||
| } | ||
|
|
||
| public function valueObjectForEvents(): Event\Code\Phpt|Event\Code\TestMethod | ||
| { | ||
| return $this->tests[0]->valueObjectForEvents(); | ||
| } | ||
|
|
||
| /** | ||
| * @phpstan-assert-if-true non-empty-list<PhptTestCase> $this->tests | ||
| */ | ||
| public function isPhptTestCase(): bool | ||
| { | ||
| return $this->tests[0] instanceof PhptTestCase; | ||
| } | ||
|
|
||
| private function runTestCase(): void | ||
| { | ||
| $defectOccurred = false; | ||
|
|
||
| foreach ($this->tests as $test) { | ||
| if ($defectOccurred) { | ||
| $test->markSkippedForErrorInPreviousRepetition(); | ||
|
|
||
| continue; | ||
| } | ||
|
|
||
| $test->run(); | ||
|
|
||
| if ($test->status()->isFailure() || $test->status()->isError()) { | ||
| $defectOccurred = true; | ||
|
|
||
| PassedTests::instance()->testMethodDidNotPass($test::class . '::' . $test->name()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private function runPhptTestCase(): void | ||
| { | ||
| $defectOccurred = false; | ||
|
|
||
| foreach ($this->tests as $test) { | ||
| if ($defectOccurred) { | ||
| EventFacade::emitter()->testSkipped( | ||
| $this->valueObjectForEvents(), | ||
| 'Test repetition failure', | ||
| ); | ||
|
|
||
| continue; | ||
| } | ||
|
|
||
| $test->run(); | ||
|
|
||
| if (!$test->passed()) { | ||
| $defectOccurred = true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.