Skip to content

Commit ee92b8a

Browse files
committed
handle when no cli arguments
1 parent 035ae6e commit ee92b8a

File tree

6 files changed

+82
-6
lines changed

6 files changed

+82
-6
lines changed

src/Framework/RepeatTestSuite.php

Lines changed: 12 additions & 2 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,25 @@ 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+
public function isPhpt(): bool
89+
{
90+
return $this->tests[0] instanceof PhptTestCase;
91+
}
92+
8393
private function runTestCase(): void
8494
{
8595
$defectOccurred = false;

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->isPhpt())) {
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/Xml/TestSuiteMapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* @throws TestDirectoryNotFoundException
4242
* @throws TestFileNotFoundException
4343
*/
44-
public function map(string $xmlConfigurationFile, TestSuiteCollection $configuredTestSuites, array $includeTestSuites, array $excludeTestSuites, int $repeatTimes): TestSuiteObject
44+
public function map(string $xmlConfigurationFile, TestSuiteCollection $configuredTestSuites, array $includeTestSuites, array $excludeTestSuites, int $repeatTimes = 1): TestSuiteObject
4545
{
4646
try {
4747
$result = TestSuiteObject::empty($xmlConfigurationFile);
@@ -134,7 +134,7 @@ public function map(string $xmlConfigurationFile, TestSuiteCollection $configure
134134
}
135135

136136
if (!$empty) {
137-
$result->addTest($testSuite);
137+
$result->addTest($testSuite, [], $repeatTimes);
138138
}
139139
}
140140

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)