Skip to content

Commit dd401e4

Browse files
Merge branch '10.5' into 11.3
2 parents dcf95a9 + cf67b2a commit dd401e4

14 files changed

+365
-1
lines changed

ChangeLog-11.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes of the PHPUnit 11.3 release series are documented in this fi
77
### Changed
88

99
* [#5957](https://github.com/sebastianbergmann/phpunit/pull/5957): Skip data provider build when requirements are not satisfied
10+
* [#5969](https://github.com/sebastianbergmann/phpunit/pull/5969): Check for requirements before creating a separate process
1011

1112
## [11.3.6] - 2024-09-19
1213

src/Framework/TestCase.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ final public function run(): void
358358
return;
359359
}
360360

361-
if (!$this->shouldRunInSeparateProcess()) {
361+
if (!$this->shouldRunInSeparateProcess() || $this->requirementsNotSatisfied()) {
362362
(new TestRunner)->run($this);
363363

364364
return;
@@ -2549,6 +2549,11 @@ private function hasExpectationOnOutput(): bool
25492549
return is_string($this->outputExpectedString) || is_string($this->outputExpectedRegex);
25502550
}
25512551

2552+
private function requirementsNotSatisfied(): bool
2553+
{
2554+
return (new Requirements)->requirementsNotSatisfiedFor(static::class, $this->methodName) !== [];
2555+
}
2556+
25522557
/**
25532558
* Creates a test stub for the specified interface or class.
25542559
*
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/4391
3+
--INI--
4+
disable_functions=proc_open
5+
--FILE--
6+
<?php declare(strict_types=1);
7+
$_SERVER['argv'][] = '--do-not-cache-result';
8+
$_SERVER['argv'][] = '--no-configuration';
9+
$_SERVER['argv'][] = __DIR__ . '/4391/RunClassInSeparateProcessClassTest.php';
10+
11+
require_once __DIR__ . '/../../bootstrap.php';
12+
13+
$buffer = \file_get_contents(__DIR__ . '/../../../src/Runner/Version.php');
14+
$start = \strpos($buffer, 'new VersionId(\'') + \strlen('new VersionId(\'');
15+
$end = \strpos($buffer, '\'', $start);
16+
$version = \substr($buffer, $start, $end - $start);
17+
18+
// Version::$version requires the proc_open function
19+
(new ReflectionProperty(PHPUnit\Runner\Version::class, 'version'))->setValue(null, $version);
20+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
21+
--EXPECTF--
22+
PHPUnit %s by Sebastian Bergmann and contributors.
23+
24+
Runtime: %s
25+
26+
SS 2 / 2 (100%)
27+
28+
Time: %s, Memory: %s
29+
30+
OK, but some tests were skipped!
31+
Tests: 2, Assertions: 0, Skipped: 2.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/4391
3+
--INI--
4+
disable_functions=proc_open
5+
--FILE--
6+
<?php declare(strict_types=1);
7+
$_SERVER['argv'][] = '--do-not-cache-result';
8+
$_SERVER['argv'][] = '--no-configuration';
9+
$_SERVER['argv'][] = __DIR__ . '/4391/RunClassInSeparateProcessMethodTest.php';
10+
11+
require_once __DIR__ . '/../../bootstrap.php';
12+
13+
$buffer = \file_get_contents(__DIR__ . '/../../../src/Runner/Version.php');
14+
$start = \strpos($buffer, 'new VersionId(\'') + \strlen('new VersionId(\'');
15+
$end = \strpos($buffer, '\'', $start);
16+
$version = \substr($buffer, $start, $end - $start);
17+
18+
// Version::$version requires the proc_open function
19+
(new ReflectionProperty(PHPUnit\Runner\Version::class, 'version'))->setValue(null, $version);
20+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
21+
--EXPECTF--
22+
PHPUnit %s by Sebastian Bergmann and contributors.
23+
24+
Runtime: %s
25+
26+
SS 2 / 2 (100%)
27+
28+
Time: %s, Memory: %s
29+
30+
OK, but some tests were skipped!
31+
Tests: 2, Assertions: 0, Skipped: 2.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/4391
3+
--INI--
4+
disable_functions=proc_open
5+
--FILE--
6+
<?php declare(strict_types=1);
7+
$_SERVER['argv'][] = '--do-not-cache-result';
8+
$_SERVER['argv'][] = '--no-configuration';
9+
$_SERVER['argv'][] = __DIR__ . '/4391/RunInSeparateProcessClassTest.php';
10+
11+
require_once __DIR__ . '/../../bootstrap.php';
12+
13+
$buffer = \file_get_contents(__DIR__ . '/../../../src/Runner/Version.php');
14+
$start = \strpos($buffer, 'new VersionId(\'') + \strlen('new VersionId(\'');
15+
$end = \strpos($buffer, '\'', $start);
16+
$version = \substr($buffer, $start, $end - $start);
17+
18+
// Version::$version requires the proc_open function
19+
(new ReflectionProperty(PHPUnit\Runner\Version::class, 'version'))->setValue(null, $version);
20+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
21+
--EXPECTF--
22+
PHPUnit %s by Sebastian Bergmann and contributors.
23+
24+
Runtime: %s
25+
26+
S 1 / 1 (100%)
27+
28+
Time: %s, Memory: %s
29+
30+
OK, but some tests were skipped!
31+
Tests: 1, Assertions: 0, Skipped: 1.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/4391
3+
--INI--
4+
disable_functions=proc_open
5+
--FILE--
6+
<?php declare(strict_types=1);
7+
$_SERVER['argv'][] = '--do-not-cache-result';
8+
$_SERVER['argv'][] = '--no-configuration';
9+
$_SERVER['argv'][] = __DIR__ . '/4391/RunInSeparateProcessMethodTest.php';
10+
11+
require_once __DIR__ . '/../../bootstrap.php';
12+
13+
$buffer = \file_get_contents(__DIR__ . '/../../../src/Runner/Version.php');
14+
$start = \strpos($buffer, 'new VersionId(\'') + \strlen('new VersionId(\'');
15+
$end = \strpos($buffer, '\'', $start);
16+
$version = \substr($buffer, $start, $end - $start);
17+
18+
// Version::$version requires the proc_open function
19+
(new ReflectionProperty(PHPUnit\Runner\Version::class, 'version'))->setValue(null, $version);
20+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
21+
--EXPECTF--
22+
PHPUnit %s by Sebastian Bergmann and contributors.
23+
24+
Runtime: %s
25+
26+
S 1 / 1 (100%)
27+
28+
Time: %s, Memory: %s
29+
30+
OK, but some tests were skipped!
31+
Tests: 1, Assertions: 0, Skipped: 1.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/4391
3+
--INI--
4+
disable_functions=proc_open
5+
--FILE--
6+
<?php declare(strict_types=1);
7+
$_SERVER['argv'][] = '--do-not-cache-result';
8+
$_SERVER['argv'][] = '--no-configuration';
9+
$_SERVER['argv'][] = __DIR__ . '/4391/RunTestsInSeparateProcessesClassTest.php';
10+
11+
require_once __DIR__ . '/../../bootstrap.php';
12+
13+
$buffer = \file_get_contents(__DIR__ . '/../../../src/Runner/Version.php');
14+
$start = \strpos($buffer, 'new VersionId(\'') + \strlen('new VersionId(\'');
15+
$end = \strpos($buffer, '\'', $start);
16+
$version = \substr($buffer, $start, $end - $start);
17+
18+
// Version::$version requires the proc_open function
19+
(new ReflectionProperty(PHPUnit\Runner\Version::class, 'version'))->setValue(null, $version);
20+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
21+
--EXPECTF--
22+
PHPUnit %s by Sebastian Bergmann and contributors.
23+
24+
Runtime: %s
25+
26+
SS 2 / 2 (100%)
27+
28+
Time: %s, Memory: %s
29+
30+
OK, but some tests were skipped!
31+
Tests: 2, Assertions: 0, Skipped: 2.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/4391
3+
--INI--
4+
disable_functions=proc_open
5+
--FILE--
6+
<?php declare(strict_types=1);
7+
$_SERVER['argv'][] = '--do-not-cache-result';
8+
$_SERVER['argv'][] = '--no-configuration';
9+
$_SERVER['argv'][] = __DIR__ . '/4391/RunTestsInSeparateProcessesMethodTest.php';
10+
11+
require_once __DIR__ . '/../../bootstrap.php';
12+
13+
$buffer = \file_get_contents(__DIR__ . '/../../../src/Runner/Version.php');
14+
$start = \strpos($buffer, 'new VersionId(\'') + \strlen('new VersionId(\'');
15+
$end = \strpos($buffer, '\'', $start);
16+
$version = \substr($buffer, $start, $end - $start);
17+
18+
// Version::$version requires the proc_open function
19+
(new ReflectionProperty(PHPUnit\Runner\Version::class, 'version'))->setValue(null, $version);
20+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
21+
--EXPECTF--
22+
PHPUnit %s by Sebastian Bergmann and contributors.
23+
24+
Runtime: %s
25+
26+
SS 2 / 2 (100%)
27+
28+
Time: %s, Memory: %s
29+
30+
OK, but some tests were skipped!
31+
Tests: 2, Assertions: 0, Skipped: 2.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture\Issue4391;
11+
12+
use Exception;
13+
use PHPUnit\Framework\Attributes\RequiresPhpunit;
14+
use PHPUnit\Framework\Attributes\RunClassInSeparateProcess;
15+
use PHPUnit\Framework\TestCase;
16+
17+
#[RunClassInSeparateProcess]
18+
#[RequiresPhpunit('< 10')]
19+
final class RunClassInSeparateProcessClassTest extends TestCase
20+
{
21+
public function testOne(): void
22+
{
23+
throw new Exception('message');
24+
}
25+
26+
public function testTwo(): void
27+
{
28+
throw new Exception('message');
29+
}
30+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture\Issue4391;
11+
12+
use Exception;
13+
use PHPUnit\Framework\Attributes\RequiresPhpunit;
14+
use PHPUnit\Framework\Attributes\RunClassInSeparateProcess;
15+
use PHPUnit\Framework\TestCase;
16+
17+
#[RunClassInSeparateProcess]
18+
final class RunClassInSeparateProcessMethodTest extends TestCase
19+
{
20+
#[RequiresPhpunit('< 10')]
21+
public function testOne(): void
22+
{
23+
throw new Exception('message');
24+
}
25+
26+
#[RequiresPhpunit('< 10')]
27+
public function testTwo(): void
28+
{
29+
throw new Exception('message');
30+
}
31+
}

0 commit comments

Comments
 (0)