Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Fix BC break for Log feature tests #42987

Merged
merged 4 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/Illuminate/Foundation/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,15 @@ public function report(Throwable $e)
$this->levels, fn ($level, $type) => $e instanceof $type, LogLevel::ERROR
);

$logger->log(
$level,
$e->getMessage(),
array_merge(
$this->exceptionContext($e),
$this->context(),
['exception' => $e]
)
$context = array_merge(
$this->exceptionContext($e),
$this->context(),
['exception' => $e]
);

method_exists($logger, $level)
? $logger->{$level}($e->getMessage(), $context)
: $logger->log($level, $e->getMessage(), $context);
}

/**
Expand Down
17 changes: 9 additions & 8 deletions tests/Foundation/FoundationExceptionsHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function testHandlerReportsExceptionAsContext()
{
$logger = m::mock(LoggerInterface::class);
$this->container->instance(LoggerInterface::class, $logger);
$logger->shouldReceive('log')->withArgs([LogLevel::ERROR, 'Exception message', m::hasKey('exception')])->once();
$logger->shouldReceive('error')->withArgs(['Exception message', m::hasKey('exception')])->once();

$this->handler->report(new RuntimeException('Exception message'));
}
Expand All @@ -83,7 +83,7 @@ public function testHandlerCallsContextMethodIfPresent()
{
$logger = m::mock(LoggerInterface::class);
$this->container->instance(LoggerInterface::class, $logger);
$logger->shouldReceive('log')->withArgs([LogLevel::ERROR, 'Exception message', m::subset(['foo' => 'bar'])])->once();
$logger->shouldReceive('error')->withArgs(['Exception message', m::subset(['foo' => 'bar'])])->once();

$this->handler->report(new ContextProvidingException('Exception message'));
}
Expand All @@ -92,7 +92,7 @@ public function testHandlerReportsExceptionWhenUnReportable()
{
$logger = m::mock(LoggerInterface::class);
$this->container->instance(LoggerInterface::class, $logger);
$logger->shouldReceive('log')->withArgs([LogLevel::ERROR, 'Exception message', m::hasKey('exception')])->once();
$logger->shouldReceive('error')->withArgs(['Exception message', m::hasKey('exception')])->once();

$this->handler->report(new UnReportableException('Exception message'));
}
Expand All @@ -101,16 +101,17 @@ public function testHandlerReportsExceptionWithCustomLogLevel()
{
$logger = m::mock(LoggerInterface::class);
$this->container->instance(LoggerInterface::class, $logger);
$logger->shouldReceive('log')->withArgs([LogLevel::CRITICAL, 'Critical message', m::hasKey('exception')])->once();
$logger->shouldReceive('log')->withArgs([LogLevel::ERROR, 'Error message', m::hasKey('exception')])->once();
$logger->shouldReceive('log')->withArgs([LogLevel::WARNING, 'Warning message', m::hasKey('exception')])->once();

$logger->shouldReceive('critical')->withArgs(['Critical message', m::hasKey('exception')])->once();
$logger->shouldReceive('error')->withArgs(['Error message', m::hasKey('exception')])->once();
$logger->shouldReceive('log')->withArgs(['custom', 'Custom message', m::hasKey('exception')])->once();

$this->handler->level(InvalidArgumentException::class, LogLevel::CRITICAL);
$this->handler->level(OutOfRangeException::class, LogLevel::WARNING);
$this->handler->level(OutOfRangeException::class, 'custom');

$this->handler->report(new InvalidArgumentException('Critical message'));
$this->handler->report(new RuntimeException('Error message'));
$this->handler->report(new OutOfRangeException('Warning message'));
$this->handler->report(new OutOfRangeException('Custom message'));
}

public function testHandlerIgnoresNotReportableExceptions()
Expand Down