Skip to content

Commit 8f80b58

Browse files
committed
handle when no cli arguments
1 parent 1773e58 commit 8f80b58

File tree

8 files changed

+95
-22
lines changed

8 files changed

+95
-22
lines changed

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Framework/RepeatTestSuite.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace PHPUnit\Framework;
1111

1212
use function count;
13+
use LogicException;
1314
use PHPUnit\Event;
1415
use PHPUnit\Event\Facade as EventFacade;
1516
use PHPUnit\Runner\Phpt\TestCase as PhptTestCase;
@@ -70,16 +71,28 @@ public function requires(): array
7071
return $this->tests[0]->requires();
7172
}
7273

73-
public function nameWithDataSet(): string
74+
public function name(): string
7475
{
75-
return $this->tests[0]->nameWithDataSet();
76+
if ($this->isPhptTestCase()) {
77+
throw new LogicException('Cannot call RepeatTestSuite::nameWithDataSet() on a PhptTestCase.');
78+
}
79+
80+
return $this->tests[0]::class . '::' . $this->tests[0]->nameWithDataSet();
7681
}
7782

7883
public function valueObjectForEvents(): Event\Code\Phpt|Event\Code\TestMethod
7984
{
8085
return $this->tests[0]->valueObjectForEvents();
8186
}
8287

88+
/**
89+
* @phpstan-assert-if-true non-empty-list<PhptTestCase> $this->tests
90+
*/
91+
public function isPhptTestCase(): bool
92+
{
93+
return $this->tests[0] instanceof PhptTestCase;
94+
}
95+
8396
private function runTestCase(): void
8497
{
8598
$defectOccurred = false;
@@ -122,12 +135,4 @@ private function runPhptTestCase(): void
122135
}
123136
}
124137
}
125-
126-
/**
127-
* @phpstan-assert-if-true non-empty-list<PhptTestCase> $this->tests
128-
*/
129-
private function isPhptTestCase(): bool
130-
{
131-
return $this->tests[0] instanceof PhptTestCase;
132-
}
133138
}

src/Runner/Filter/NameFilterIterator.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use function preg_match;
1414
use function sprintf;
1515
use function substr;
16+
use PHPUnit\Framework\RepeatTestSuite;
1617
use PHPUnit\Framework\Test;
1718
use PHPUnit\Framework\TestSuite;
1819
use PHPUnit\Runner\Phpt\TestCase as PhptTestCase;
@@ -56,11 +57,15 @@ public function accept(): bool
5657
return true;
5758
}
5859

59-
if ($test instanceof PhptTestCase) {
60+
if ($test instanceof PhptTestCase || ($test instanceof RepeatTestSuite && $test->isPhptTestCase())) {
6061
return false;
6162
}
6263

63-
$name = $test::class . '::' . $test->nameWithDataSet();
64+
if ($test instanceof RepeatTestSuite) {
65+
$name = $test->name();
66+
} else {
67+
$name = $test::class . '::' . $test->nameWithDataSet();
68+
}
6469

6570
$accepted = @preg_match($this->regularExpression, $name, $matches) === 1;
6671

src/TextUI/Configuration/TestSuiteBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public function build(Configuration $configuration): TestSuite
7979
$configuration->testSuite(),
8080
$configuration->ignoreTestSelectionInXmlConfiguration() ? [] : $configuration->includeTestSuites(),
8181
$configuration->ignoreTestSelectionInXmlConfiguration() ? [] : $configuration->excludeTestSuites(),
82+
$configuration->repeatTimes(),
8283
);
8384
}
8485

src/TextUI/Configuration/Xml/TestSuiteMapper.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@
3636
* @param non-empty-string $xmlConfigurationFile
3737
* @param list<non-empty-string> $includeTestSuites
3838
* @param list<non-empty-string> $excludeTestSuites
39+
* @param positive-int $repeatTimes
3940
*
4041
* @throws RuntimeException
4142
* @throws TestDirectoryNotFoundException
4243
* @throws TestFileNotFoundException
4344
*/
44-
public function map(string $xmlConfigurationFile, TestSuiteCollection $configuredTestSuites, array $includeTestSuites, array $excludeTestSuites): TestSuiteObject
45+
public function map(string $xmlConfigurationFile, TestSuiteCollection $configuredTestSuites, array $includeTestSuites, array $excludeTestSuites, int $repeatTimes = 1): TestSuiteObject
4546
{
4647
try {
4748
$result = TestSuiteObject::empty($xmlConfigurationFile);
@@ -101,7 +102,7 @@ public function map(string $xmlConfigurationFile, TestSuiteCollection $configure
101102
$processed[$file] = $testSuiteName;
102103
$empty = false;
103104

104-
$testSuite->addTestFile($file, $groups);
105+
$testSuite->addTestFile($file, $groups, $repeatTimes);
105106
}
106107
}
107108

@@ -130,11 +131,11 @@ public function map(string $xmlConfigurationFile, TestSuiteCollection $configure
130131
$processed[$file->path()] = $testSuiteName;
131132
$empty = false;
132133

133-
$testSuite->addTestFile($file->path(), $file->groups());
134+
$testSuite->addTestFile($file->path(), $file->groups(), $repeatTimes);
134135
}
135136

136137
if (!$empty) {
137-
$result->addTest($testSuite);
138+
$result->addTest($testSuite, [], $repeatTimes);
138139
}
139140
}
140141

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="../../../../phpunit.xsd"
4+
cacheResult="false"
5+
>
6+
<testsuites>
7+
<testsuite name="default">
8+
<file>RepeatTest.php</file>
9+
</testsuite>
10+
</testsuites>
11+
</phpunit>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Repeat option
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--configuration';
7+
$_SERVER['argv'][] = __DIR__ . '/_files/phpunit.xml';
8+
$_SERVER['argv'][] = '--repeat';
9+
$_SERVER['argv'][] = '2';
10+
$_SERVER['argv'][] = '--filter';
11+
$_SERVER['argv'][] = 'test1';
12+
13+
require __DIR__ . '/../../bootstrap.php';
14+
15+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
16+
--EXPECTF--
17+
PHPUnit %s by Sebastian Bergmann and contributors.
18+
19+
Runtime: %s
20+
Configuration: %s/tests/end-to-end/repeat/_files/phpunit.xml
21+
22+
.. 2 / 2 (100%)
23+
24+
Time: %s, Memory: %s MB
25+
26+
OK (2 tests, 2 assertions)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Repeat option
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--configuration';
7+
$_SERVER['argv'][] = __DIR__ . '/_files/phpunit.xml';
8+
$_SERVER['argv'][] = '--repeat';
9+
$_SERVER['argv'][] = '2';
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+
Runtime: %s
18+
Configuration: %s/tests/end-to-end/repeat/_files/phpunit.xml
19+
20+
.... 4 / 4 (100%)
21+
22+
Time: %s, Memory: %s MB
23+
24+
OK (4 tests, 4 assertions)

0 commit comments

Comments
 (0)