Skip to content

Commit eb4829f

Browse files
committed
Handle test suite loaded from path with --repeat
1 parent 1f5c46c commit eb4829f

File tree

5 files changed

+56
-6
lines changed

5 files changed

+56
-6
lines changed

src/Framework/TestSuite.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public function addTestSuite(ReflectionClass $testClass, array $groups = [], int
216216
);
217217
}
218218

219-
$this->addTest(self::fromClassReflector($testClass, $groups), $groups, $repeat);
219+
$this->addTest(self::fromClassReflector($testClass, $groups, $repeat), $groups, $repeat);
220220
}
221221

222222
/**
@@ -240,6 +240,7 @@ public function addTestFile(string $filename, array $groups = [], int $repeat =
240240
$this->addTestSuite(
241241
(new TestSuiteLoader)->load($filename),
242242
$groups,
243+
$repeat,
243244
);
244245
}
245246
} catch (RunnerException $e) {
@@ -256,10 +257,10 @@ public function addTestFile(string $filename, array $groups = [], int $repeat =
256257
*
257258
* @throws Exception
258259
*/
259-
public function addTestFiles(iterable $fileNames): void
260+
public function addTestFiles(iterable $fileNames, int $repeat = 1): void
260261
{
261262
foreach ($fileNames as $filename) {
262-
$this->addTestFile((string) $filename);
263+
$this->addTestFile((string) $filename, [], $repeat);
263264
}
264265
}
265266

src/TextUI/Configuration/TestSuiteBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private function testSuiteFromPath(string $path, array $suffixes, int $repeat, ?
112112
$suite = TestSuite::empty('CLI Arguments');
113113
}
114114

115-
$suite->addTestFiles($files);
115+
$suite->addTestFiles($files, $repeat);
116116

117117
return $suite;
118118
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace directory;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class RepeatInDirectoryTest extends TestCase
8+
{
9+
public function test1(): void
10+
{
11+
self::assertTrue(true);
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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'][] = '2';
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+
Runtime: %s
18+
19+
.. 2 / 2 (100%)
20+
21+
Time: %s, Memory: %s MB
22+
23+
OK (2 tests, 2 assertions)

tests/end-to-end/repeat/phpt-failure-and-success.phpt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,21 @@ PHPUnit %s by Sebastian Bergmann and contributors.
1616

1717
Runtime: %s
1818

19-
.. 2 / 2 (100%)
19+
FS.. 4 / 4 (100%)
2020

2121
Time: %s, Memory: %s MB
2222

23-
OK (2 tests, 2 assertions)
23+
There was 1 failure:
24+
25+
1) /home/niko/works/github.com/sebastianbergmann/phpunit/tests/end-to-end/repeat/_files/phpt/failure.phpt
26+
Failed asserting that string matches format description.
27+
--- Expected
28+
+++ Actual
29+
@@ @@
30+
-ko
31+
+ok
32+
33+
/home/niko/works/github.com/sebastianbergmann/phpunit/tests/end-to-end/repeat/_files/phpt/failure.phpt:8
34+
35+
FAILURES!
36+
Tests: 4, Assertions: 3, Failures: 1, Skipped: 1.

0 commit comments

Comments
 (0)