Skip to content

Commit fe9fa87

Browse files
ArturGoldynsebastianbergmann
authored andcommitted
Issue #2591 - test process isolation with and without preserving global state.
1 parent 3e3c42c commit fe9fa87

7 files changed

+141
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--TEST--
2+
GH-2591: Test method process isolation without preserving global state and without loaded bootstrap.
3+
--FILE--
4+
<?php
5+
6+
$_SERVER['argv'][1] = '--no-configuration';
7+
$_SERVER['argv'][2] = '--bootstrap';
8+
$_SERVER['argv'][3] = __DIR__ . '/2591/bootstrapNoBootstrap.php';
9+
$_SERVER['argv'][4] = __DIR__ . '/2591/SeparateFunctionNoPreserveTest.php';
10+
11+
require __DIR__ . '/../../bootstrap.php';
12+
PHPUnit\TextUI\Command::main();
13+
--EXPECTF--
14+
PHPUnit %s by Sebastian Bergmann and contributors.
15+
16+
EE 2 / 2 (100%)
17+
18+
Time: %s, Memory: %s
19+
20+
There were 2 errors:
21+
22+
1) Issue2591Test::testChangedGlobalString
23+
PHPUnit\Framework\Exception: PHP Fatal error: Class 'PhpUnit\Framework\TestCase' not found in %s/tests/Regression/GitHub/2591/SeparateFunctionNoPreserveTest.php on line 8
24+
PHP Stack trace:
25+
PHP 1. {main}() -:0
26+
PHP 2. __phpunit_run_isolated_test() -:108
27+
PHP 3. require_once() -:30
28+
29+
Fatal error: Class 'PhpUnit\Framework\TestCase' not found in %s/tests/Regression/GitHub/2591/SeparateFunctionNoPreserveTest.php on line 8
30+
31+
Call Stack:
32+
%s %s 1. {main}() -:0
33+
%s %s 2. __phpunit_run_isolated_test() -:108
34+
%s %s 3. require_once('%s/tests/Regression/GitHub/2591/SeparateFunctionNoPreserveTest.php') -:30
35+
36+
2) Issue2591Test::testGlobalString
37+
PHPUnit\Framework\Exception: PHP Fatal error: Class 'PhpUnit\Framework\TestCase' not found in %s/tests/Regression/GitHub/2591/SeparateFunctionNoPreserveTest.php on line 8
38+
PHP Stack trace:
39+
PHP 1. {main}() -:0
40+
PHP 2. __phpunit_run_isolated_test() -:108
41+
PHP 3. require_once() -:30
42+
43+
Fatal error: Class 'PhpUnit\Framework\TestCase' not found in %s/tests/Regression/GitHub/2591/SeparateFunctionNoPreserveTest.php on line 8
44+
45+
Call Stack:
46+
%s %s 1. {main}() -:0
47+
%s %s 2. __phpunit_run_isolated_test() -:108
48+
%s %s 3. require_once('%s/tests/Regression/GitHub/2591/SeparateFunctionNoPreserveTest.php') -:30
49+
50+
ERRORS!
51+
Tests: 2, Assertions: 0, Errors: 2.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-2591: Test method process isolation without preserving global state and with loaded bootstrap.
3+
--FILE--
4+
<?php
5+
6+
$_SERVER['argv'][1] = '--no-configuration';
7+
$_SERVER['argv'][2] = '--bootstrap';
8+
$_SERVER['argv'][3] = __DIR__ . '/2591/bootstrapWithBootstrap.php';
9+
$_SERVER['argv'][4] = __DIR__ . '/2591/SeparateFunctionNoPreserveTest.php';
10+
11+
require __DIR__ . '/../../bootstrap.php';
12+
PHPUnit\TextUI\Command::main();
13+
--EXPECTF--
14+
PHPUnit %s by Sebastian Bergmann and contributors.
15+
16+
.. 2 / 2 (100%)
17+
18+
Time: %s, Memory: %s
19+
20+
OK (2 tests, 2 assertions)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-2591: Test method process isolation with preserving global state and with loaded bootstrap.
3+
--FILE--
4+
<?php
5+
6+
$_SERVER['argv'][1] = '--no-configuration';
7+
$_SERVER['argv'][2] = '--bootstrap';
8+
$_SERVER['argv'][3] = __DIR__ . '/2591/bootstrapWithBootstrap.php';
9+
$_SERVER['argv'][4] = __DIR__ . '/2591/SeparateFunctionPreserveTest.php';
10+
11+
require __DIR__ . '/../../bootstrap.php';
12+
PHPUnit\TextUI\Command::main();
13+
--EXPECTF--
14+
PHPUnit %s by Sebastian Bergmann and contributors.
15+
16+
.. 2 / 2 (100%)
17+
18+
Time: %s, Memory: %s
19+
20+
OK (2 tests, 2 assertions)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
use PhpUnit\Framework\TestCase;
3+
4+
/**
5+
* @runTestsInSeparateProcesses
6+
* @preserveGlobalState disabled
7+
*/
8+
class Issue2591Test extends TestCase
9+
{
10+
public function testChangedGlobalString()
11+
{
12+
$GLOBALS['globalString'] = "Hello!";
13+
$this->assertEquals('Hello!', $GLOBALS['globalString']);
14+
}
15+
16+
public function testGlobalString()
17+
{
18+
$this->assertEquals('Hello', $GLOBALS['globalString']);
19+
}
20+
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
use PhpUnit\Framework\TestCase;
3+
4+
/**
5+
* @runTestsInSeparateProcesses
6+
* @preserveGlobalState enabled
7+
*/
8+
class Issue2591Test extends TestCase
9+
{
10+
public function testChangedGlobalString()
11+
{
12+
$GLOBALS['globalString'] = "Hello!";
13+
$this->assertEquals('Hello!', $GLOBALS['globalString']);
14+
}
15+
16+
public function testGlobalString()
17+
{
18+
$this->assertEquals('Hello', $GLOBALS['globalString']);
19+
}
20+
21+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
$globalString = 'Hello';
3+
4+
// require __DIR__ . '/../../../bootstrap.php';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
$globalString = 'Hello';
3+
4+
require __DIR__ . '/../../../bootstrap.php';

0 commit comments

Comments
 (0)