Skip to content

Commit e079b71

Browse files
committed
--repeat value should be a positive integer
1 parent eb4829f commit e079b71

File tree

7 files changed

+45
-1
lines changed

7 files changed

+45
-1
lines changed

src/Framework/TestBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* @param ReflectionClass<TestCase> $theClass
3737
* @param non-empty-string $methodName
3838
* @param list<non-empty-string> $groups
39+
* @param positive-int $repeat
3940
*
4041
* @throws InvalidDataProviderException
4142
*/
@@ -86,6 +87,7 @@ public function build(ReflectionClass $theClass, string $methodName, array $grou
8687
* @param array<ProvidedData> $data
8788
* @param array{backupGlobals: ?true, backupGlobalsExcludeList: list<string>, backupStaticProperties: ?true, backupStaticPropertiesExcludeList: array<string,list<string>>} $backupSettings
8889
* @param list<non-empty-string> $groups
90+
* @param positive-int $repeat
8991
*/
9092
private function buildDataProviderTestSuite(string $methodName, string $className, array $data, bool $runTestInSeparateProcess, ?bool $preserveGlobalState, array $backupSettings, array $groups, int $repeat = 1): DataProviderTestSuite
9193
{

src/Framework/TestSuite.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public static function empty(string $name): static
9696
/**
9797
* @param ReflectionClass<TestCase> $class
9898
* @param list<non-empty-string> $groups
99+
* @param positive-int $repeat
99100
*/
100101
public static function fromClassReflector(ReflectionClass $class, array $groups = [], int $repeat = 1): static
101102
{
@@ -145,6 +146,7 @@ final private function __construct(string $name)
145146
* Adds a test to the suite.
146147
*
147148
* @param list<non-empty-string> $groups
149+
* @param positive-int $repeat
148150
*/
149151
public function addTest(Test $test, array $groups = [], int $repeat = 1): void
150152
{
@@ -192,6 +194,7 @@ public function addTest(Test $test, array $groups = [], int $repeat = 1): void
192194
*
193195
* @param ReflectionClass<TestCase> $testClass
194196
* @param list<non-empty-string> $groups
197+
* @param positive-int $repeat
195198
*
196199
* @throws Exception
197200
*/
@@ -228,6 +231,7 @@ public function addTestSuite(ReflectionClass $testClass, array $groups = [], int
228231
* leaving the current test run untouched.
229232
*
230233
* @param list<non-empty-string> $groups
234+
* @param positive-int $repeat
231235
*
232236
* @throws Exception
233237
*/
@@ -254,6 +258,7 @@ public function addTestFile(string $filename, array $groups = [], int $repeat =
254258
* Wrapper for addTestFile() that adds multiple test files.
255259
*
256260
* @param iterable<string> $fileNames
261+
* @param positive-int $repeat
257262
*
258263
* @throws Exception
259264
*/
@@ -508,6 +513,7 @@ public function isForTestClass(): bool
508513
/**
509514
* @param ReflectionClass<TestCase> $class
510515
* @param list<non-empty-string> $groups
516+
* @param positive-int $repeat
511517
*
512518
* @throws Exception
513519
*/

src/TextUI/Configuration/Cli/Builder.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,13 @@ public function fromParameters(array $parameters): Configuration
12141214
break;
12151215

12161216
case '--repeat':
1217-
$repeat = (int) $option[1]; // todo: superior to 1
1217+
$repeat = (int) $option[1];
1218+
1219+
if ($repeat < 1) {
1220+
throw new Exception(
1221+
'The value for the --repeat option must be a positive integer',
1222+
);
1223+
}
12181224

12191225
break;
12201226

src/TextUI/Configuration/Cli/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
* @param ?non-empty-list<non-empty-string> $testSuffixes
196196
* @param ?non-empty-list<non-empty-string> $coverageFilter
197197
* @param ?non-empty-list<non-empty-string> $extensions
198+
* @param positive-int $repeat
198199
*/
199200
public function __construct(array $arguments, ?bool $all, ?string $atLeastVersion, ?bool $backupGlobals, ?bool $backupStaticProperties, ?bool $beStrictAboutChangesToGlobalState, ?string $bootstrap, ?string $cacheDirectory, ?bool $cacheResult, bool $checkPhpConfiguration, bool $checkVersion, ?string $colors, null|int|string $columns, ?string $configurationFile, ?string $coverageClover, ?string $coverageCobertura, ?string $coverageCrap4J, ?string $coverageHtml, ?string $coverageOpenClover, ?string $coveragePhp, ?string $coverageText, ?bool $coverageTextShowUncoveredFiles, ?bool $coverageTextShowOnlySummary, ?string $coverageXml, ?bool $pathCoverage, bool $warmCoverageCache, ?int $defaultTimeLimit, ?bool $disableCodeCoverageIgnore, ?bool $disallowTestOutput, ?bool $enforceTimeLimit, ?array $excludeGroups, ?int $executionOrder, ?int $executionOrderDefects, ?bool $failOnAllIssues, ?bool $failOnDeprecation, ?bool $failOnPhpunitDeprecation, ?bool $failOnPhpunitNotice, ?bool $failOnPhpunitWarning, ?bool $failOnEmptyTestSuite, ?bool $failOnIncomplete, ?bool $failOnNotice, ?bool $failOnRisky, ?bool $failOnSkipped, ?bool $failOnWarning, ?bool $doNotFailOnDeprecation, ?bool $doNotFailOnPhpunitDeprecation, ?bool $doNotFailOnPhpunitNotice, ?bool $doNotFailOnPhpunitWarning, ?bool $doNotFailOnEmptyTestSuite, ?bool $doNotFailOnIncomplete, ?bool $doNotFailOnNotice, ?bool $doNotFailOnRisky, ?bool $doNotFailOnSkipped, ?bool $doNotFailOnWarning, ?bool $stopOnDefect, ?bool $stopOnDeprecation, ?string $specificDeprecationToStopOn, ?bool $stopOnError, ?bool $stopOnFailure, ?bool $stopOnIncomplete, ?bool $stopOnNotice, ?bool $stopOnRisky, ?bool $stopOnSkipped, ?bool $stopOnWarning, ?string $filter, ?string $excludeFilter, ?string $generateBaseline, ?string $useBaseline, bool $ignoreBaseline, bool $generateConfiguration, bool $migrateConfiguration, ?array $groups, ?array $testsCovering, ?array $testsUsing, ?array $testsRequiringPhpExtension, bool $help, ?string $includePath, ?array $iniSettings, ?string $junitLogfile, ?string $otrLogfile, ?bool $includeGitInformation, bool $listGroups, bool $listSuites, bool $listTestFiles, bool $listTests, ?string $listTestsXml, ?bool $noCoverage, ?bool $noExtensions, ?bool $noOutput, ?bool $noProgress, ?bool $noResults, ?bool $noLogging, ?bool $processIsolation, ?int $randomOrderSeed, ?bool $reportUselessTests, ?bool $resolveDependencies, ?bool $reverseList, ?bool $stderr, ?bool $strictCoverage, ?string $teamcityLogfile, ?string $testdoxHtmlFile, ?string $testdoxTextFile, ?array $testSuffixes, ?string $testSuite, ?string $excludeTestSuite, bool $useDefaultConfiguration, ?bool $displayDetailsOnAllIssues, ?bool $displayDetailsOnIncompleteTests, ?bool $displayDetailsOnSkippedTests, ?bool $displayDetailsOnTestsThatTriggerDeprecations, ?bool $displayDetailsOnPhpunitDeprecations, ?bool $displayDetailsOnPhpunitNotices, ?bool $displayDetailsOnTestsThatTriggerErrors, ?bool $displayDetailsOnTestsThatTriggerNotices, ?bool $displayDetailsOnTestsThatTriggerWarnings, bool $version, ?array $coverageFilter, ?string $logEventsText, ?string $logEventsVerboseText, ?bool $printerTeamCity, ?bool $testdoxPrinter, ?bool $testdoxPrinterSummary, bool $debug, bool $withTelemetry, ?array $extensions, int $repeat)
200201
{
@@ -2580,6 +2581,9 @@ public function debug(): bool
25802581
return $this->debug;
25812582
}
25822583

2584+
/**
2585+
* @return positive-int
2586+
*/
25832587
public function repeat(): int
25842588
{
25852589
return $this->repeat;

src/TextUI/Configuration/Configuration.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@
194194
*/
195195
private ?string $generateBaseline;
196196
private bool $debug;
197+
/**
198+
* @var positive-int
199+
*/
197200
private int $repeat;
198201
private bool $withTelemetry;
199202

@@ -215,6 +218,7 @@
215218
* @param non-empty-list<non-empty-string> $testSuffixes
216219
* @param null|non-empty-string $generateBaseline
217220
* @param non-negative-int $shortenArraysForExportThreshold
221+
* @param positive-int $repeat
218222
*/
219223
public function __construct(array $cliArguments, ?string $configurationFile, ?string $bootstrap, array $bootstrapForTestSuite, bool $cacheResult, ?string $cacheDirectory, ?string $coverageCacheDirectory, Source $source, string $testResultCacheFile, ?string $coverageClover, ?string $coverageCobertura, ?string $coverageCrap4j, int $coverageCrap4jThreshold, ?string $coverageHtml, int $coverageHtmlLowUpperBound, int $coverageHtmlHighLowerBound, string $coverageHtmlColorSuccessLow, string $coverageHtmlColorSuccessMedium, string $coverageHtmlColorSuccessHigh, string $coverageHtmlColorWarning, string $coverageHtmlColorDanger, ?string $coverageHtmlCustomCssFile, ?string $coverageOpenClover, ?string $coveragePhp, ?string $coverageText, bool $coverageTextShowUncoveredFiles, bool $coverageTextShowOnlySummary, ?string $coverageXml, bool $pathCoverage, bool $ignoreDeprecatedCodeUnitsFromCodeCoverage, bool $disableCodeCoverageIgnore, bool $failOnAllIssues, bool $failOnDeprecation, bool $failOnPhpunitDeprecation, bool $failOnPhpunitNotice, bool $failOnPhpunitWarning, bool $failOnEmptyTestSuite, bool $failOnIncomplete, bool $failOnNotice, bool $failOnRisky, bool $failOnSkipped, bool $failOnWarning, bool $doNotFailOnDeprecation, bool $doNotFailOnPhpunitDeprecation, bool $doNotFailOnPhpunitNotice, bool $doNotFailOnPhpunitWarning, bool $doNotFailOnEmptyTestSuite, bool $doNotFailOnIncomplete, bool $doNotFailOnNotice, bool $doNotFailOnRisky, bool $doNotFailOnSkipped, bool $doNotFailOnWarning, bool $stopOnDefect, bool $stopOnDeprecation, ?string $specificDeprecationToStopOn, bool $stopOnError, bool $stopOnFailure, bool $stopOnIncomplete, bool $stopOnNotice, bool $stopOnRisky, bool $stopOnSkipped, bool $stopOnWarning, bool $outputToStandardErrorStream, int $columns, bool $noExtensions, ?string $pharExtensionDirectory, array $extensionBootstrappers, bool $backupGlobals, bool $backupStaticProperties, bool $beStrictAboutChangesToGlobalState, bool $colors, bool $processIsolation, bool $enforceTimeLimit, int $defaultTimeLimit, int $timeoutForSmallTests, int $timeoutForMediumTests, int $timeoutForLargeTests, bool $reportUselessTests, bool $strictCoverage, bool $disallowTestOutput, bool $displayDetailsOnAllIssues, bool $displayDetailsOnIncompleteTests, bool $displayDetailsOnSkippedTests, bool $displayDetailsOnTestsThatTriggerDeprecations, bool $displayDetailsOnPhpunitDeprecations, bool $displayDetailsOnPhpunitNotices, bool $displayDetailsOnTestsThatTriggerErrors, bool $displayDetailsOnTestsThatTriggerNotices, bool $displayDetailsOnTestsThatTriggerWarnings, bool $reverseDefectList, bool $requireCoverageMetadata, bool $noProgress, bool $noResults, bool $noOutput, int $executionOrder, int $executionOrderDefects, bool $resolveDependencies, ?string $logfileTeamcity, ?string $logfileJunit, ?string $logfileOtr, bool $includeGitInformationInOtrLogfile, ?string $logfileTestdoxHtml, ?string $logfileTestdoxText, ?string $logEventsText, ?string $logEventsVerboseText, bool $teamCityOutput, bool $testDoxOutput, bool $testDoxOutputSummary, ?array $testsCovering, ?array $testsUsing, ?array $testsRequiringPhpExtension, ?string $filter, ?string $excludeFilter, array $groups, array $excludeGroups, int $randomOrderSeed, bool $includeUncoveredFiles, TestSuiteCollection $testSuite, string $includeTestSuite, string $excludeTestSuite, ?string $defaultTestSuite, bool $ignoreTestSelectionInXmlConfiguration, array $testSuffixes, Php $php, bool $controlGarbageCollector, int $numberOfTestsBeforeGarbageCollection, ?string $generateBaseline, bool $debug, int $repeat, bool $withTelemetry, int $shortenArraysForExportThreshold)
220224
{
@@ -1516,6 +1520,9 @@ public function debug(): bool
15161520
return $this->debug;
15171521
}
15181522

1523+
/**
1524+
* @return positive-int
1525+
*/
15191526
public function repeat(): int
15201527
{
15211528
return $this->repeat;

src/TextUI/Configuration/TestSuiteBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public function build(Configuration $configuration): TestSuite
9090
/**
9191
* @param non-empty-string $path
9292
* @param list<non-empty-string> $suffixes
93+
* @param positive-int $repeat
9394
*
9495
* @throws \PHPUnit\Framework\Exception
9596
*/
@@ -137,6 +138,7 @@ private function testSuiteFromPath(string $path, array $suffixes, int $repeat, ?
137138
/**
138139
* @param list<non-empty-string> $paths
139140
* @param list<non-empty-string> $suffixes
141+
* @param positive-int $repeat
140142
*
141143
* @throws \PHPUnit\Framework\Exception
142144
*/
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Repeat option
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--repeat';
8+
$_SERVER['argv'][] = 'foo';
9+
$_SERVER['argv'][] = __DIR__ . '/_files/directory';
10+
11+
require __DIR__ . '/../../bootstrap.php';
12+
13+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
14+
--EXPECTF--
15+
PHPUnit %s by Sebastian Bergmann and contributors.
16+
17+
The value for the --repeat option must be a positive integer

0 commit comments

Comments
 (0)