Skip to content

Commit 2b04154

Browse files
authored
Merge pull request #412 from mvorisek/test_separate_process
Add tests for scenarios where tests are running in separate processes
2 parents f9fc12a + c0caef1 commit 2b04154

File tree

6 files changed

+125
-30
lines changed

6 files changed

+125
-30
lines changed

test/EndToEnd/Version10/DefaultConfiguration/SleeperTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,28 @@ public static function provideMillisecondsGreaterThanDefaultMaximumDuration(): i
359359
];
360360
}
361361
}
362+
363+
#[Framework\Attributes\RunInSeparateProcess]
364+
public function testSleeperSleepsShorterThanDefaultMaximumDurationWhenRunningInSeparateProcess(): void
365+
{
366+
$milliseconds = 50;
367+
368+
$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);
369+
370+
$sleeper->sleep();
371+
372+
self::assertSame($milliseconds, $sleeper->milliseconds());
373+
}
374+
375+
#[Framework\Attributes\RunInSeparateProcess]
376+
public function testSleeperSleepsLongerThanDefaultMaximumDurationWhenRunningInSeparateProcess(): void
377+
{
378+
$milliseconds = 750;
379+
380+
$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);
381+
382+
$sleeper->sleep();
383+
384+
self::assertSame($milliseconds, $sleeper->milliseconds());
385+
}
362386
}

test/EndToEnd/Version10/DefaultConfiguration/test.phpt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ use PHPUnit\TextUI;
99

1010
$_SERVER['argv'][] = '--configuration=test/EndToEnd/Version10/DefaultConfiguration/phpunit.xml';
1111

12-
require_once __DIR__ . '/../../../../vendor/autoload.php';
12+
/**
13+
* @see https://github.com/sebastianbergmann/phpunit/blob/10.0.0/src/Framework/TestRunner.php#L288-L290
14+
*/
15+
define('PHPUNIT_COMPOSER_INSTALL', __DIR__ . '/../../../../vendor/autoload.php');
16+
17+
require_once PHPUNIT_COMPOSER_INSTALL;
1318

1419
$application = new TextUI\Application();
1520

@@ -21,9 +26,9 @@ Runtime: %s
2126
Configuration: %Stest/EndToEnd/Version10/DefaultConfiguration/phpunit.xml
2227
Random %seed: %s
2328

24-
..................... 21 / 21 (100%)
29+
....................... 23 / 23 (100%)
2530

26-
Detected 11 tests that took longer than expected.
31+
Detected 12 tests that took longer than expected.
2732

2833
1. 1.2%s (1.150) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAttributeWithValidMaximumDurationAndSlowThresholdAnnotation
2934
2. 1.1%s (1.100) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAttribute
@@ -34,10 +39,10 @@ Detected 11 tests that took longer than expected.
3439
7. 0.9%s (0.800) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidMaximumDurationAnnotation
3540
8. 0.8%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidMaximumDurationAnnotation
3641
9. 0.8%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithUselessDocBlock
37-
10. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDuration
42+
10. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWhenRunningInSeparateProcess
3843

39-
There is 1 additional slow test that is not listed here.
44+
There are 2 additional slow tests that are not listed here.
4045

4146
Time: %s, Memory: %s
4247

43-
OK (21 tests, 21 assertions)
48+
OK (23 tests, 23 assertions)

test/EndToEnd/Version8/DefaultConfiguration/SleeperTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,32 @@ public static function provideMillisecondsGreaterThanDefaultMaximumDuration(): i
304304
];
305305
}
306306
}
307+
308+
/**
309+
* @runInSeparateProcess
310+
*/
311+
public function testSleeperSleepsShorterThanDefaultMaximumDurationWhenRunningInSeparateProcess(): void
312+
{
313+
$milliseconds = 50;
314+
315+
$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);
316+
317+
$sleeper->sleep();
318+
319+
self::assertSame($milliseconds, $sleeper->milliseconds());
320+
}
321+
322+
/**
323+
* @runInSeparateProcess
324+
*/
325+
public function testSleeperSleepsLongerThanDefaultMaximumDurationWhenRunningInSeparateProcess(): void
326+
{
327+
$milliseconds = 750;
328+
329+
$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);
330+
331+
$sleeper->sleep();
332+
333+
self::assertSame($milliseconds, $sleeper->milliseconds());
334+
}
307335
}

test/EndToEnd/Version8/DefaultConfiguration/test.phpt

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ use PHPUnit\TextUI;
99

1010
$_SERVER['argv'][] = '--configuration=test/EndToEnd/Version8/DefaultConfiguration/phpunit.xml';
1111

12-
require_once __DIR__ . '/../../../../vendor/autoload.php';
12+
/**
13+
* @see https://github.com/sebastianbergmann/phpunit/blob/8.5.19/src/Framework/TestCase.php#L754C1-L756
14+
*/
15+
define('PHPUNIT_COMPOSER_INSTALL', __DIR__ . '/../../../../vendor/autoload.php');
16+
17+
require_once PHPUNIT_COMPOSER_INSTALL;
1318

1419
PHPUnit\TextUI\Command::main();
1520
--EXPECTF--
@@ -19,23 +24,23 @@ Runtime: %s
1924
Configuration: %Stest/EndToEnd/Version8/DefaultConfiguration/phpunit.xml
2025
Random %seed: %s
2126

22-
................... 19 / 19 (100%)
27+
..................... 21 / 21 (100%)
2328

24-
Detected 11 tests that took longer than expected.
29+
Detected 12 tests that took longer than expected.
2530

2631
1. 1.2%s (1.000) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidSlowThresholdAndMaximumDurationAnnotation
2732
2. 1.1%s (1.000) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidMaximumDurationAndSlowThresholdAnnotation
2833
3. 1.1%s (0.900) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanSlowThresholdFromAnnotationWithValidSlowThresholdAnnotation
29-
4. 1.0%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidSlowThresholdAnnotation
30-
5. 1.0%s (0.800) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidMaximumDurationAnnotation
31-
6. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidMaximumDurationAnnotation
32-
7. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithUselessDocBlock
33-
8. 0.8%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDuration
34-
9. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #2 (600)
35-
10. 0.6%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #1 (550)
34+
4. 1.0%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWhenRunningInSeparateProcess
35+
5. 1.0%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidSlowThresholdAnnotation
36+
6. 1.0%s (0.800) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidMaximumDurationAnnotation
37+
7. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidMaximumDurationAnnotation
38+
8. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithUselessDocBlock
39+
9. 0.8%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDuration
40+
10. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version8\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #2 (600)
3641

37-
There is 1 additional slow test that is not listed here.
42+
There are 2 additional slow tests that are not listed here.
3843

3944
Time: %s, Memory: %s
4045

41-
OK (19 tests, 19 assertions)
46+
OK (21 tests, 21 assertions)

test/EndToEnd/Version9/DefaultConfiguration/SleeperTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,32 @@ public static function provideMillisecondsGreaterThanDefaultMaximumDuration(): i
304304
];
305305
}
306306
}
307+
308+
/**
309+
* @runInSeparateProcess
310+
*/
311+
public function testSleeperSleepsShorterThanDefaultMaximumDurationWhenRunningInSeparateProcess(): void
312+
{
313+
$milliseconds = 50;
314+
315+
$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);
316+
317+
$sleeper->sleep();
318+
319+
self::assertSame($milliseconds, $sleeper->milliseconds());
320+
}
321+
322+
/**
323+
* @runInSeparateProcess
324+
*/
325+
public function testSleeperSleepsLongerThanDefaultMaximumDurationWhenRunningInSeparateProcess(): void
326+
{
327+
$milliseconds = 750;
328+
329+
$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);
330+
331+
$sleeper->sleep();
332+
333+
self::assertSame($milliseconds, $sleeper->milliseconds());
334+
}
307335
}

test/EndToEnd/Version9/DefaultConfiguration/test.phpt

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ use PHPUnit\TextUI;
99

1010
$_SERVER['argv'][] = '--configuration=test/EndToEnd/Version9/DefaultConfiguration/phpunit.xml';
1111

12-
require_once __DIR__ . '/../../../../vendor/autoload.php';
12+
/**
13+
* @see https://github.com/sebastianbergmann/phpunit/blob/9.4.3/src/Framework/TestCase.php#L799-L801
14+
*/
15+
define('PHPUNIT_COMPOSER_INSTALL', __DIR__ . '/../../../../vendor/autoload.php');
16+
17+
require_once PHPUNIT_COMPOSER_INSTALL;
1318

1419
PHPUnit\TextUI\Command::main();
1520
--EXPECTF--
@@ -19,23 +24,23 @@ Runtime: %s
1924
Configuration: %Stest/EndToEnd/Version9/DefaultConfiguration/phpunit.xml
2025
Random %seed: %s
2126

22-
................... 19 / 19 (100%)
27+
..................... 21 / 21 (100%)
2328

24-
Detected 11 tests that took longer than expected.
29+
Detected 12 tests that took longer than expected.
2530

2631
1. 1.2%s (1.000) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidSlowThresholdAndMaximumDurationAnnotation
2732
2. 1.1%s (1.000) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidMaximumDurationAndSlowThresholdAnnotation
2833
3. 1.1%s (0.900) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanSlowThresholdFromAnnotationWithValidSlowThresholdAnnotation
29-
4. 1.0%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidSlowThresholdAnnotation
30-
5. 1.0%s (0.800) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidMaximumDurationAnnotation
31-
6. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidMaximumDurationAnnotation
32-
7. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithUselessDocBlock
33-
8. 0.8%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDuration
34-
9. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #2 (600)
35-
10. 0.6%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #1 (550)
34+
4. 1.0%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWhenRunningInSeparateProcess
35+
5. 1.0%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidSlowThresholdAnnotation
36+
6. 1.0%s (0.800) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromAnnotationWithValidMaximumDurationAnnotation
37+
7. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithInvalidMaximumDurationAnnotation
38+
8. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithUselessDocBlock
39+
9. 0.8%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDuration
40+
10. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version9\DefaultConfiguration\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #2 (600)
3641

37-
There is 1 additional slow test that is not listed here.
42+
There are 2 additional slow tests that are not listed here.
3843

3944
Time: %s, Memory: %s
4045

41-
OK (19 tests, 19 assertions)
46+
OK (21 tests, 21 assertions)

0 commit comments

Comments
 (0)