diff --git a/includes/application.php b/includes/application.php index 94a02fd2..3a6ed9a6 100644 --- a/includes/application.php +++ b/includes/application.php @@ -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); } diff --git a/src/Helpers/ConfigureEnvironmentServiceProvider.php b/src/Helpers/ConfigureEnvironmentServiceProvider.php index 9f244fc7..a01490b8 100644 --- a/src/Helpers/ConfigureEnvironmentServiceProvider.php +++ b/src/Helpers/ConfigureEnvironmentServiceProvider.php @@ -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); + } } diff --git a/tests/Unit/Helpers/ConfigureEnvironmentServiceProviderTest.php b/tests/Unit/Helpers/ConfigureEnvironmentServiceProviderTest.php index 30313c33..a202c64f 100644 --- a/tests/Unit/Helpers/ConfigureEnvironmentServiceProviderTest.php +++ b/tests/Unit/Helpers/ConfigureEnvironmentServiceProviderTest.php @@ -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(); } }