Skip to content

Commit 1bd85e8

Browse files
committed
add test which uses #[RunTestsInSeparateProcesses]
1 parent 32e3acb commit 1bd85e8

File tree

8 files changed

+92
-7
lines changed

8 files changed

+92
-7
lines changed

src/Framework/RepeatTestSuite.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(PhptTestCase|TestCase $test, int $times)
3636
$tests = [];
3737

3838
for ($i = 0; $i < $times; $i++) {
39-
$tests[] = $test;
39+
$tests[] = clone $test;
4040
}
4141

4242
$this->tests = $tests;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
11+
use PHPUnit\Framework\TestCase;
12+
13+
#[RunTestsInSeparateProcesses]
14+
final class RepeatInIsolationTest extends TestCase
15+
{
16+
private Closure $notCloneableFixture;
17+
private int $counter;
18+
19+
public function __clone()
20+
{
21+
if (isset($this->notCloneableFixture)) {
22+
throw new LogicException('Cannot clone RepeatInIsolationTest because it contains a non-cloneable fixture.');
23+
}
24+
}
25+
26+
protected function setUp(): void
27+
{
28+
$this->counter = 0;
29+
$this->notCloneableFixture = static fn () => true;
30+
}
31+
32+
public function test1(): void
33+
{
34+
$this->assertTrue(($this->notCloneableFixture)());
35+
36+
$this->counter++;
37+
$this->assertSame(1, $this->counter);
38+
}
39+
40+
public function test2(): void
41+
{
42+
$this->assertTrue(($this->notCloneableFixture)());
43+
44+
$this->counter++;
45+
$this->assertSame(1, $this->counter);
46+
}
47+
}

tests/end-to-end/repeat/_files/RepeatTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,28 @@
1111

1212
final class RepeatTest extends TestCase
1313
{
14+
private Closure $notCloneableFixture;
15+
private int $counter;
16+
17+
protected function setUp(): void
18+
{
19+
$this->counter = 0;
20+
$this->notCloneableFixture = static fn () => true;
21+
}
22+
1423
public function test1(): void
1524
{
16-
$this->assertTrue(true);
25+
$this->assertTrue(($this->notCloneableFixture)());
26+
27+
$this->counter++;
28+
$this->assertSame(1, $this->counter);
1729
}
1830

1931
public function test2(): void
2032
{
21-
$this->assertTrue(true);
33+
$this->assertTrue(($this->notCloneableFixture)());
34+
35+
$this->counter++;
36+
$this->assertSame(1, $this->counter);
2237
}
2338
}

tests/end-to-end/repeat/filter.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ Runtime: %s
2222

2323
Time: %s, Memory: %s MB
2424

25-
OK (2 tests, 2 assertions)
25+
OK (2 tests, 4 assertions)
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/RepeatInIsolationTest.php';
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+
.... 4 / 4 (100%)
20+
21+
Time: %s, Memory: %s MB
22+
23+
OK (4 tests, 8 assertions)

tests/end-to-end/repeat/no-cli-argument-filtered.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ Configuration: %s/tests/end-to-end/repeat/_files/phpunit.xml
2323

2424
Time: %s, Memory: %s MB
2525

26-
OK (2 tests, 2 assertions)
26+
OK (2 tests, 4 assertions)

tests/end-to-end/repeat/no-cli-argument.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ Configuration: %s/tests/end-to-end/repeat/_files/phpunit.xml
2121

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

24-
OK (4 tests, 4 assertions)
24+
OK (4 tests, 8 assertions)

tests/end-to-end/repeat/simple-repeat.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ Runtime: %s
2020

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

23-
OK (4 tests, 4 assertions)
23+
OK (4 tests, 8 assertions)

0 commit comments

Comments
 (0)