Last active
April 1, 2018 12:19
-
-
Save mkasberg/ce7611c602e5f445b730493577b9c8e5 to your computer and use it in GitHub Desktop.
PHPUnit Hides Errors After set_error_handler() Called
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
<?php | |
class CustomLogger { | |
public function __construct() { | |
// Try commenting out this line: | |
set_error_handler(array($this, 'handleError')); | |
} | |
public function __desctruct() { | |
restore_error_handler(); | |
} | |
public function handleError($errno, $errstr, $errfile = null, $errline = null, $errcontext = null) { | |
// Do stuff. | |
// Log something. | |
return true; | |
} | |
} |
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
<?php | |
/** | |
* CustomLogger, Thing, CustomLoggerTest, ThingTest | |
* | |
* Place all 4 files in the same directory. Run `phpunit .`. No errors will be shown. | |
* Now run `phpunit --process-isolation .`. Errors will be shown. | |
* Also try `phpunit ThingTest.php`. Errors will be shown. | |
* Tested with PHPUnit 5.7.15. | |
*/ | |
require_once "CustomLogger.php"; | |
class CustomLoggerTest extends PHPUnit_Framework_TestCase { | |
public function testSomething() { | |
$logger = new CustomLogger(); | |
$this->assertTrue(true); | |
} | |
public function testSomethingElse() { | |
$logger = new CustomLogger(); | |
$this->assertTrue(true); | |
} | |
} |
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
<?php | |
class Thing { | |
public function doStuff() { | |
// Do stuff. | |
} | |
} |
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
<?php | |
require_once "Thing.php"; | |
class ThingTest extends PHPUnit_Framework_TestCase { | |
public function testTheThing() { | |
array_keys(10); // Throw an error! | |
$this->assertTrue(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment