Skip to content

Commit b57b0b5

Browse files
Merge branch '12.3'
2 parents cfa08bf + c1c1438 commit b57b0b5

File tree

4 files changed

+140
-19
lines changed

4 files changed

+140
-19
lines changed

tests/end-to-end/regression/5592-process-isolation.phpt

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ https://github.com/sebastianbergmann/phpunit/pull/5592
55
$_SERVER['argv'][] = '--do-not-cache-result';
66
$_SERVER['argv'][] = '--no-configuration';
77
$_SERVER['argv'][] = '--process-isolation';
8-
$_SERVER['argv'][] = __DIR__ . '/5592/Issue5592Test.php';
8+
$_SERVER['argv'][] = __DIR__ . '/5592/Issue5592TestIsolation.php';
99

10-
set_exception_handler(static fn () => null);
10+
function global5592IsolationExceptionHandler(Throwable $exception): void
11+
{
12+
}
13+
14+
set_exception_handler('global5592IsolationExceptionHandler');
1115

1216
require_once __DIR__ . '/../../bootstrap.php';
1317
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
@@ -22,34 +26,34 @@ Time: %s, Memory: %s
2226

2327
There were 4 failures:
2428

25-
1) PHPUnit\TestFixture\Issue5592Test::testAddedErrorHandler
29+
1) PHPUnit\TestFixture\Issue5592TestIsolation::testAddedErrorHandler
2630
Failed asserting that false is true.
2731

28-
%sIssue5592Test.php:%i
32+
%sIssue5592TestIsolation.php:%i
2933

30-
2) PHPUnit\TestFixture\Issue5592Test::testRemovedErrorHandler
34+
2) PHPUnit\TestFixture\Issue5592TestIsolation::testRemovedErrorHandler
3135
Failed asserting that false is true.
3236

33-
%sIssue5592Test.php:%i
37+
%sIssue5592TestIsolation.php:%i
3438

35-
3) PHPUnit\TestFixture\Issue5592Test::testAddedExceptionHandler
39+
3) PHPUnit\TestFixture\Issue5592TestIsolation::testAddedExceptionHandler
3640
Failed asserting that false is true.
3741

38-
%sIssue5592Test.php:%i
42+
%sIssue5592TestIsolation.php:%i
3943

40-
4) PHPUnit\TestFixture\Issue5592Test::testRemovedExceptionHandler
44+
4) PHPUnit\TestFixture\Issue5592TestIsolation::testRemovedExceptionHandler
4145
Failed asserting that false is true.
4246

43-
%sIssue5592Test.php:%i
47+
%sIssue5592TestIsolation.php:%i
4448

4549
--
4650

4751
There was 1 risky test:
4852

49-
1) PHPUnit\TestFixture\Issue5592Test::testRemovedErrorHandler
53+
1) PHPUnit\TestFixture\Issue5592TestIsolation::testRemovedErrorHandler
5054
Test code or tested code removed error handlers other than its own
5155

52-
%sIssue5592Test.php:%i
56+
%sIssue5592TestIsolation.php:%i
5357

5458
FAILURES!
55-
Tests: 6, Assertions: 6, Failures: 4, Risky: 1.
59+
Tests: 6, Assertions: 10, Failures: 4, Risky: 1.

tests/end-to-end/regression/5592.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ $_SERVER['argv'][] = '--do-not-cache-result';
66
$_SERVER['argv'][] = '--no-configuration';
77
$_SERVER['argv'][] = __DIR__ . '/5592/Issue5592Test.php';
88

9-
set_exception_handler(static fn () => null);
9+
function global5592ExceptionHandler(Throwable $exception): void
10+
{
11+
}
12+
13+
set_exception_handler('global5592ExceptionHandler');
1014

1115
require_once __DIR__ . '/../../bootstrap.php';
1216
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
@@ -66,4 +70,4 @@ Test code or tested code removed exception handlers other than its own
6670
%sIssue5592Test.php:%i
6771

6872
FAILURES!
69-
Tests: 6, Assertions: 6, Failures: 4, Risky: 4.
73+
Tests: 6, Assertions: 10, Failures: 4, Risky: 4.

tests/end-to-end/regression/5592/Issue5592Test.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,25 @@
1414
use function set_error_handler;
1515
use function set_exception_handler;
1616
use PHPUnit\Framework\TestCase;
17+
use PHPUnit\Runner\ErrorHandler;
18+
use Throwable;
1719

1820
class Issue5592Test extends TestCase
1921
{
2022
public function testAddedAndRemovedErrorHandler(): void
2123
{
22-
set_error_handler(static fn () => false);
24+
$previous = set_error_handler([$this, 'addedAndRemovedErrorHandler']);
2325
restore_error_handler();
26+
27+
$this->assertInstanceOf(ErrorHandler::class, $previous);
2428
$this->assertTrue(true);
2529
}
2630

2731
public function testAddedErrorHandler(): void
2832
{
29-
set_error_handler(static fn () => false);
33+
$previous = set_error_handler([$this, 'addedErrorHandler']);
34+
35+
$this->assertInstanceOf(ErrorHandler::class, $previous);
3036
$this->assertTrue(false);
3137
}
3238

@@ -38,14 +44,18 @@ public function testRemovedErrorHandler(): void
3844

3945
public function testAddedAndRemovedExceptionHandler(): void
4046
{
41-
set_exception_handler(static fn () => null);
47+
$previous = set_exception_handler([$this, 'addedAndRemovedExceptionHandler']);
4248
restore_exception_handler();
49+
50+
$this->assertSame('global5592ExceptionHandler', $previous);
4351
$this->assertTrue(true);
4452
}
4553

4654
public function testAddedExceptionHandler(): void
4755
{
48-
set_exception_handler(static fn () => null);
56+
$previous = set_exception_handler([$this, 'addedExceptionHandler']);
57+
58+
$this->assertSame('global5592ExceptionHandler', $previous);
4959
$this->assertTrue(false);
5060
}
5161

@@ -54,4 +64,22 @@ public function testRemovedExceptionHandler(): void
5464
restore_exception_handler();
5565
$this->assertTrue(false);
5666
}
67+
68+
public function addedAndRemovedErrorHandler($errno, $errstr, $errfile, $errline): bool
69+
{
70+
return false;
71+
}
72+
73+
public function addedErrorHandler($errno, $errstr, $errfile, $errline): bool
74+
{
75+
return false;
76+
}
77+
78+
public function addedAndRemovedExceptionHandler(Throwable $exception): void
79+
{
80+
}
81+
82+
public function addedExceptionHandler(Throwable $exception): void
83+
{
84+
}
5785
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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;
11+
12+
use function restore_error_handler;
13+
use function restore_exception_handler;
14+
use function set_error_handler;
15+
use function set_exception_handler;
16+
use PHPUnit\Framework\TestCase;
17+
use PHPUnit\Runner\ErrorHandler;
18+
use Throwable;
19+
20+
class Issue5592TestIsolation extends TestCase
21+
{
22+
public function testAddedAndRemovedErrorHandler(): void
23+
{
24+
$previous = set_error_handler([$this, 'addedAndRemovedErrorHandler']);
25+
restore_error_handler();
26+
27+
$this->assertInstanceOf(ErrorHandler::class, $previous);
28+
$this->assertTrue(true);
29+
}
30+
31+
public function testAddedErrorHandler(): void
32+
{
33+
$previous = set_error_handler([$this, 'addedErrorHandler']);
34+
35+
$this->assertInstanceOf(ErrorHandler::class, $previous);
36+
$this->assertTrue(false);
37+
}
38+
39+
public function testRemovedErrorHandler(): void
40+
{
41+
restore_error_handler();
42+
$this->assertTrue(false);
43+
}
44+
45+
public function testAddedAndRemovedExceptionHandler(): void
46+
{
47+
$previous = set_exception_handler([$this, 'addedAndRemovedExceptionHandler']);
48+
restore_exception_handler();
49+
50+
$this->assertNull($previous);
51+
$this->assertTrue(true);
52+
}
53+
54+
public function testAddedExceptionHandler(): void
55+
{
56+
$previous = set_exception_handler([$this, 'addedExceptionHandler']);
57+
58+
$this->assertNull($previous);
59+
$this->assertTrue(false);
60+
}
61+
62+
public function testRemovedExceptionHandler(): void
63+
{
64+
restore_exception_handler();
65+
$this->assertTrue(false);
66+
}
67+
68+
public function addedAndRemovedErrorHandler($errno, $errstr, $errfile, $errline): bool
69+
{
70+
return false;
71+
}
72+
73+
public function addedErrorHandler($errno, $errstr, $errfile, $errline): bool
74+
{
75+
return false;
76+
}
77+
78+
public function addedAndRemovedExceptionHandler(Throwable $exception): void
79+
{
80+
}
81+
82+
public function addedExceptionHandler(Throwable $exception): void
83+
{
84+
}
85+
}

0 commit comments

Comments
 (0)