Skip to content
Permalink
Browse files

BUG fix ErrorControlChain causing errors to be displayed if display_e…

…rrors in php.ini is false

Fixes #5250
  • Loading branch information...
Damian Mooyman
Damian Mooyman committed Mar 31, 2016
1 parent 20d1167 commit 6ec26562019454483db79132a5c076cfa87dfe34
Showing with 58 additions and 2 deletions.
  1. +14 −2 core/startup/ErrorControlChain.php
  2. +44 −0 tests/core/startup/ErrorControlChainTest.php
@@ -36,9 +36,21 @@ public function setErrored($error) {
$this->error = (bool)$error;
}
/**
* Sets whether errors are suppressed or not
* Notes:
* - Errors cannot be suppressed if not handling errors.
* - Errors cannot be un-suppressed if original mode dis-allowed visible errors
*
* @param bool $suppression
*/
public function setSuppression($suppression) {
$this->suppression = (bool)$suppression;
if ($this->handleFatalErrors) ini_set('display_errors', !$suppression);
// Don't modify errors unless handling fatal errors, and if errors were
// originally allowed to be displayed.
if ($this->handleFatalErrors && $this->originalDisplayErrors) {
ini_set('display_errors', !$suppression);
}
}
/**
@@ -112,7 +124,7 @@ public function execute() {
$this->handleFatalErrors = true;
$this->originalDisplayErrors = ini_get('display_errors');
ini_set('display_errors', !$this->suppression);
$this->setSuppression($this->suppression);
$this->step();
}
@@ -63,7 +63,11 @@ function executeInSubprocess($includeStderr = false) {
class ErrorControlChainTest extends SapphireTest {
protected $displayErrors = null;
function setUp() {
$this->displayErrors = (bool)ini_get('display_errors');
// Check we can run PHP at all
$null = is_writeable('/dev/null') ? '/dev/null' : 'NUL';
exec("php -v 2> $null", $out, $rv);
@@ -76,8 +80,48 @@ function setUp() {
parent::setUp();
}
public function tearDown() {
if($this->displayErrors !== null) {
ini_set('display_errors', $this->displayErrors);
$this->displayErrors = null;
}
parent::tearDown(); // TODO: Change the autogenerated stub
}
function testErrorSuppression() {
// Errors disabled by default
ini_set('display_errors', false);
$chain = new ErrorControlChain();
$whenNotSuppressed = null;
$whenSuppressed = null;
$chain->then(function($chain) use(&$whenNotSuppressed, &$whenSuppressed) {
$chain->setSuppression(true);
$whenSuppressed = ini_get('display_errors');
$chain->setSuppression(false);
$whenNotSuppressed = ini_get('display_errors');
})->execute();
// Disabled errors never un-disable
$this->assertFalse((bool)$whenNotSuppressed);
$this->assertFalse((bool)$whenSuppressed);
// Errors enabled by default
ini_set('display_errors', true);
$chain = new ErrorControlChain();
$whenNotSuppressed = null;
$whenSuppressed = null;
$chain->then(function($chain) use(&$whenNotSuppressed, &$whenSuppressed) {
$chain->setSuppression(true);
$whenSuppressed = ini_get('display_errors');
$chain->setSuppression(false);
$whenNotSuppressed = ini_get('display_errors');
})->execute();
// Errors can be suppressed an un-suppressed when initially enabled
$this->assertTrue((bool)$whenNotSuppressed);
$this->assertFalse((bool)$whenSuppressed);
// Fatal error
$chain = new ErrorControlChainTest_Chain();

0 comments on commit 6ec2656

Please sign in to comment.
You can’t perform that action at this time.