From d65260d12656e41a371a054a60dbe6e2163ebcd5 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 22 Aug 2022 15:41:28 +0100 Subject: [PATCH] Fixes creation of deprecations channel (#43812) --- .../Foundation/Bootstrap/HandleExceptions.php | 8 +++-- .../Bootstrap/HandleExceptionsTest.php | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php b/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php index 8667f39b23e4..c7b1c98dbe0d 100644 --- a/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php +++ b/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php @@ -144,9 +144,11 @@ protected function ensureDeprecationLoggerIsConfigured() $this->ensureNullLogDriverIsConfigured(); - $options = $config->get('logging.deprecations'); - - $driver = is_array($options) ? $options['channel'] : ($options ?? 'null'); + if (is_array($options = $config->get('logging.deprecations'))) { + $driver = $options['channel'] ?? 'null'; + } else { + $driver = $options ?? 'null'; + } $config->set('logging.channels.deprecations', $config->get("logging.channels.{$driver}")); }); diff --git a/tests/Foundation/Bootstrap/HandleExceptionsTest.php b/tests/Foundation/Bootstrap/HandleExceptionsTest.php index 08af8b1dffd3..9495d8e18901 100644 --- a/tests/Foundation/Bootstrap/HandleExceptionsTest.php +++ b/tests/Foundation/Bootstrap/HandleExceptionsTest.php @@ -98,6 +98,36 @@ public function testPhpDeprecationsWithStackTraces() ); } + public function testNullValueAsChannelUsesNullDriver() + { + $logger = m::mock(LogManager::class); + $this->app->instance(LogManager::class, $logger); + + $this->config->set('logging.deprecations', [ + 'channel' => null, + 'trace' => false, + ]); + + $logger->shouldReceive('channel')->with('deprecations')->andReturnSelf(); + $logger->shouldReceive('warning')->with(sprintf('%s in %s on line %s', + 'str_contains(): Passing null to parameter #2 ($needle) of type string is deprecated', + '/home/user/laravel/routes/web.php', + 17 + )); + + $this->handleExceptions->handleError( + E_DEPRECATED, + 'str_contains(): Passing null to parameter #2 ($needle) of type string is deprecated', + '/home/user/laravel/routes/web.php', + 17 + ); + + $this->assertEquals([ + 'driver' => 'monolog', + 'handler' => NullHandler::class, + ], $this->config->get('logging.channels.deprecations')); + } + public function testUserDeprecations() { $logger = m::mock(LogManager::class);