Moved error reporting settings to ConfigureEnvironmentServiceProvider

This commit is contained in:
Igor Scheller 2020-04-21 12:19:31 +02:00 committed by msquare
parent 2b1ccb6406
commit 2605204af8
3 changed files with 35 additions and 7 deletions

View File

@ -28,8 +28,4 @@ if (config('environment') == 'development') {
$errorHandler = $app->get('error.handler');
$errorHandler->setEnvironment(Handler::ENV_DEVELOPMENT);
$app->bind(HandlerInterface::class, 'error.handler.development');
ini_set('display_errors', true);
error_reporting(E_ALL);
} else {
ini_set('display_errors', false);
}

View File

@ -15,6 +15,12 @@ class ConfigureEnvironmentServiceProvider extends ServiceProvider
$timezone = new CarbonTimeZone($config->get('timezone'));
$this->setTimeZone($timezone);
$this->displayErrors(false);
if ($config->get('environment') == 'development') {
$this->displayErrors(true);
$this->errorReporting(E_ALL);
}
}
/**
@ -26,4 +32,22 @@ class ConfigureEnvironmentServiceProvider extends ServiceProvider
ini_set('date.timezone', $timeZone);
date_default_timezone_set($timeZone);
}
/**
* @param bool $displayErrors
* @codeCoverageIgnore
*/
protected function displayErrors(bool $displayErrors)
{
ini_set('display_errors', $displayErrors);
}
/**
* @param int $errorReporting
* @codeCoverageIgnore
*/
protected function errorReporting(int $errorReporting)
{
error_reporting($errorReporting);
}
}

View File

@ -15,21 +15,29 @@ class ConfigureEnvironmentServiceProviderTest extends ServiceProviderTest
*/
public function testRegister()
{
$config = new Config(['timezone' => 'Australia/Eucla']);
$config = new Config(['timezone' => 'Australia/Eucla', 'environment' => 'production']);
$this->app->instance('config', $config);
/** @var ConfigureEnvironmentServiceProvider|MockObject $serviceProvider */
$serviceProvider = $this->getMockBuilder(ConfigureEnvironmentServiceProvider::class)
->setConstructorArgs([$this->app])
->onlyMethods(['setTimeZone'])
->onlyMethods(['setTimeZone', 'displayErrors', 'errorReporting'])
->getMock();
$serviceProvider->expects($this->once())
$serviceProvider->expects($this->exactly(2))
->method('setTimeZone')
->willReturnCallback(function (CarbonTimeZone $timeZone) {
$this->assertEquals('Australia/Eucla', $timeZone->getName());
});
$serviceProvider->expects($this->exactly(3))
->method('displayErrors')
->withConsecutive([false], [false], [true]);
$serviceProvider->expects($this->exactly(1))
->method('errorReporting')
->with(E_ALL);
$serviceProvider->register();
$config->set('environment', 'development');
$serviceProvider->register();
}
}