Moved error reporting settings to ConfigureEnvironmentServiceProvider

main
Igor Scheller 5 years ago committed by msquare
parent 2b1ccb6406
commit 2605204af8

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

@ -15,6 +15,12 @@ class ConfigureEnvironmentServiceProvider extends ServiceProvider
$timezone = new CarbonTimeZone($config->get('timezone')); $timezone = new CarbonTimeZone($config->get('timezone'));
$this->setTimeZone($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); ini_set('date.timezone', $timeZone);
date_default_timezone_set($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);
}
} }

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

Loading…
Cancel
Save