From 9476a142063bd12459b9bfceafa196a0aca3e633 Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Fri, 23 Oct 2026 18:35:11 +0400 Subject: [PATCH 1/2] [#599] Allow psr/log 3 next to psr/log 2 composer.json accepts psr/log ^2.0 || ^3.0. psr/log 3 could not be installed while symfony/console 5.4 conflicted with it; the console is on 6.4 now. Both versions declare string|\Stringable for the message, so the Logger methods declare it natively too. --- composer.json | 2 +- src/Logger/Logger.php | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 3780188ef..37ddf0f99 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "dflydev/dot-access-data": "^3.0", "php-debugbar/php-debugbar": "^2.2", "phpmailer/phpmailer": "^7.1", - "psr/log": "^2.0", + "psr/log": "^2.0 || ^3.0", "rakibtg/sleekdb": "^2.13", "swagger-api/swagger-ui": "^5.32", "zircote/swagger-php": "^5.8", diff --git a/src/Logger/Logger.php b/src/Logger/Logger.php index deb91fdfc..b94f6a52f 100644 --- a/src/Logger/Logger.php +++ b/src/Logger/Logger.php @@ -13,6 +13,7 @@ use Quantum\Logger\Contracts\ReportableInterface; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; +use Stringable; /** * Class Logger @@ -35,7 +36,7 @@ public function getAdapter(): ReportableInterface /** * @inheritDoc */ - public function emergency($message, array $context = []): void + public function emergency(string|Stringable $message, array $context = []): void { $this->log(LogLevel::EMERGENCY, $message, $context); } @@ -43,7 +44,7 @@ public function emergency($message, array $context = []): void /** * @inheritDoc */ - public function alert($message, array $context = []): void + public function alert(string|Stringable $message, array $context = []): void { $this->log(LogLevel::ALERT, $message, $context); } @@ -51,7 +52,7 @@ public function alert($message, array $context = []): void /** * @inheritDoc */ - public function critical($message, array $context = []): void + public function critical(string|Stringable $message, array $context = []): void { $this->log(LogLevel::CRITICAL, $message, $context); } @@ -59,7 +60,7 @@ public function critical($message, array $context = []): void /** * @inheritDoc */ - public function error($message, array $context = []): void + public function error(string|Stringable $message, array $context = []): void { $this->log(LogLevel::ERROR, $message, $context); } @@ -67,7 +68,7 @@ public function error($message, array $context = []): void /** * @inheritDoc */ - public function warning($message, array $context = []): void + public function warning(string|Stringable $message, array $context = []): void { $this->log(LogLevel::WARNING, $message, $context); } @@ -75,7 +76,7 @@ public function warning($message, array $context = []): void /** * @inheritDoc */ - public function notice($message, array $context = []): void + public function notice(string|Stringable $message, array $context = []): void { $this->log(LogLevel::NOTICE, $message, $context); } @@ -83,7 +84,7 @@ public function notice($message, array $context = []): void /** * @inheritDoc */ - public function info($message, array $context = []): void + public function info(string|Stringable $message, array $context = []): void { $this->log(LogLevel::INFO, $message, $context); } @@ -91,7 +92,7 @@ public function info($message, array $context = []): void /** * @inheritDoc */ - public function debug($message, array $context = []): void + public function debug(string|Stringable $message, array $context = []): void { $this->log(LogLevel::DEBUG, $message, $context); } @@ -99,7 +100,7 @@ public function debug($message, array $context = []): void /** * @inheritDoc */ - public function log($level, $message, array $context = []): void + public function log($level, string|Stringable $message, array $context = []): void { if (is_debug_mode() || LoggerConfig::getLogLevel($level) >= LoggerConfig::getAppLogLevel()) { $this->adapter->report($level, $message, $context); From 63965ef94f8ee65c7d2b876d096ec88586e859cd Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Fri, 23 Oct 2026 18:41:51 +0400 Subject: [PATCH 2/2] [#599] Test every PSR-3 level method of the Logger emergency(), alert() and critical() were never called by a test, because the global helpers cover only the other five levels. The tests check that each level method reports its message with its level, and that a Stringable message is accepted. --- tests/Unit/Logger/LoggerTest.php | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/Unit/Logger/LoggerTest.php b/tests/Unit/Logger/LoggerTest.php index d88542d90..aa40beab8 100644 --- a/tests/Unit/Logger/LoggerTest.php +++ b/tests/Unit/Logger/LoggerTest.php @@ -6,6 +6,8 @@ use Quantum\Logger\Adapters\MessageAdapter; use Quantum\Tests\Unit\AppTestCase; use Quantum\Logger\Logger; +use Psr\Log\LogLevel; +use Stringable; class LoggerTest extends AppTestCase { @@ -40,4 +42,45 @@ public function testLoggerLogReportsTheMessageToTheAdapter(): void $this->assertSame([['info' => 'Test message'], ['error' => 'Error message']], $this->adapter->getMessages()); } + + /** + * @dataProvider levelMethodProvider + */ + public function testLoggerLevelMethodReportsTheMessageWithItsLevel(string $method, string $level): void + { + $this->logger->$method('Some message'); + + $this->assertSame([[$level => 'Some message']], $this->adapter->getMessages()); + } + + public function testLoggerAcceptsAStringableMessage(): void + { + $message = new class () implements Stringable { + public function __toString(): string + { + return 'From an object'; + } + }; + + $this->logger->critical($message); + + $this->assertSame([['critical' => $message]], $this->adapter->getMessages()); + } + + /** + * @return array + */ + public function levelMethodProvider(): array + { + return [ + 'emergency' => ['emergency', LogLevel::EMERGENCY], + 'alert' => ['alert', LogLevel::ALERT], + 'critical' => ['critical', LogLevel::CRITICAL], + 'error' => ['error', LogLevel::ERROR], + 'warning' => ['warning', LogLevel::WARNING], + 'notice' => ['notice', LogLevel::NOTICE], + 'info' => ['info', LogLevel::INFO], + 'debug' => ['debug', LogLevel::DEBUG], + ]; + } }