Skip to content

Commit 6671293

Browse files
committed
Do not throw an exception when the samlAuthenticationLogger is used before forAuthentication() is called on it
This obscures the original log message
1 parent ae75742 commit 6671293

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/Monolog/SamlAuthenticationLogger.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,10 @@ public function log($level, $message, array $context = []): void
9696
*/
9797
private function modifyContext(array $context): array
9898
{
99-
if (!$this->sari) {
100-
throw new RuntimeException('Authentication logging context is unknown');
99+
if ($this->sari) {
100+
$context['sari'] = $this->sari;
101101
}
102102

103-
$context['sari'] = $this->sari;
104-
105103
return $context;
106104
}
107105
}

src/Tests/Unit/Monolog/SamlAuthenticationLoggerTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ public function it_returns_a_logger_for_an_authentication(): void
4747
/**
4848
* @test
4949
*/
50-
public function it_errors_when_no_authentication(): void
50+
public function it_does_not_throw_when_no_authentication(): void
5151
{
52-
self::expectException(RuntimeException::class);
53-
$logger = new SamlAuthenticationLogger(m::mock(LoggerInterface::class));
52+
$innerLogger = m::mock(LoggerInterface::class);
53+
$innerLogger->shouldReceive('emergency')->with('message2', [])->once();
54+
55+
$logger = new SamlAuthenticationLogger($innerLogger);
5456
$logger->emergency('message2');
5557
}
5658
}

0 commit comments

Comments
 (0)