Skip to content

Commit

Permalink
Fixes creation of deprecations channel (#43812)
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro authored Aug 22, 2022
1 parent a0cd9d2 commit d65260d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Illuminate/Foundation/Bootstrap/HandleExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}"));
});
Expand Down
30 changes: 30 additions & 0 deletions tests/Foundation/Bootstrap/HandleExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d65260d

Please sign in to comment.