-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check and restore error/exception global handlers
- Loading branch information
1 parent
549f23c
commit 93aa92b
Showing
5 changed files
with
272 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--TEST-- | ||
https://github.com/sebastianbergmann/phpunit/pull/5592 | ||
--FILE-- | ||
<?php declare(strict_types=1); | ||
$_SERVER['argv'][] = '--do-not-cache-result'; | ||
$_SERVER['argv'][] = '--no-configuration'; | ||
$_SERVER['argv'][] = __DIR__ . '/5592/Issue5592Test.php'; | ||
|
||
set_exception_handler(static fn () => null); | ||
|
||
require_once __DIR__ . '/../../bootstrap.php'; | ||
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']); | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
Runtime: %s | ||
|
||
.FF.FF 6 / 6 (100%) | ||
|
||
Time: %s, Memory: %s | ||
|
||
There were 4 failures: | ||
|
||
1) PHPUnit\TestFixture\Issue5592Test::testAddedErrorHandler | ||
Failed asserting that false is true. | ||
|
||
%sIssue5592Test.php:%i | ||
|
||
2) PHPUnit\TestFixture\Issue5592Test::testRemovedErrorHandler | ||
Failed asserting that false is true. | ||
|
||
%sIssue5592Test.php:%i | ||
|
||
3) PHPUnit\TestFixture\Issue5592Test::testAddedExceptionHandler | ||
Failed asserting that false is true. | ||
|
||
%sIssue5592Test.php:%i | ||
|
||
4) PHPUnit\TestFixture\Issue5592Test::testRemovedExceptionHandler | ||
Failed asserting that false is true. | ||
|
||
%sIssue5592Test.php:%i | ||
|
||
-- | ||
|
||
There were 4 risky tests: | ||
|
||
1) PHPUnit\TestFixture\Issue5592Test::testAddedErrorHandler | ||
Test code or tested code did not remove its own error handlers | ||
|
||
%sIssue5592Test.php:%i | ||
|
||
2) PHPUnit\TestFixture\Issue5592Test::testRemovedErrorHandler | ||
Test code or tested code removed error handlers other than its own | ||
|
||
%sIssue5592Test.php:%i | ||
|
||
3) PHPUnit\TestFixture\Issue5592Test::testAddedExceptionHandler | ||
Test code or tested code did not remove its own exception handlers | ||
|
||
%sIssue5592Test.php:%i | ||
|
||
4) PHPUnit\TestFixture\Issue5592Test::testRemovedExceptionHandler | ||
Test code or tested code removed exception handlers other than its own | ||
|
||
%sIssue5592Test.php:%i | ||
|
||
FAILURES! | ||
Tests: 6, Assertions: 6, Failures: 4, Risky: 4. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\TestFixture; | ||
|
||
use function restore_error_handler; | ||
use function restore_exception_handler; | ||
use function set_error_handler; | ||
use function set_exception_handler; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class Issue5592Test extends TestCase | ||
{ | ||
public function testAddedAndRemovedErrorHandler(): void | ||
{ | ||
set_error_handler(static fn () => false); | ||
restore_error_handler(); | ||
$this->assertTrue(true); | ||
} | ||
|
||
public function testAddedErrorHandler(): void | ||
{ | ||
set_error_handler(static fn () => false); | ||
$this->assertTrue(false); | ||
} | ||
|
||
public function testRemovedErrorHandler(): void | ||
{ | ||
restore_error_handler(); | ||
$this->assertTrue(false); | ||
} | ||
|
||
public function testAddedAndRemovedExceptionHandler(): void | ||
{ | ||
set_exception_handler(static fn () => null); | ||
restore_exception_handler(); | ||
$this->assertTrue(true); | ||
} | ||
|
||
public function testAddedExceptionHandler(): void | ||
{ | ||
set_exception_handler(static fn () => null); | ||
$this->assertTrue(false); | ||
} | ||
|
||
public function testRemovedExceptionHandler(): void | ||
{ | ||
restore_exception_handler(); | ||
$this->assertTrue(false); | ||
} | ||
} |