fig/log-test
Testing utilities for PSR-3 (psr/log): includes LoggerInterfaceTest for verifying LoggerInterface compliance and TestLogger mock for unit tests. Intended for dev/test use, with versions aligned to psr/log 1.x–3.x compatibility.
Start by installing fig/log-test as a require-dev dependency. Use version ^1.1 for psr/log ≥2.0 (including 3.x), and ^1.0 for PHP 7.x compatibility with psr/log ^1.1.14. Once installed, the two primary utilities are:
Psr\Log\Test\TestLogger: A test-friendly logger implementation that records all log calls in memory.Psr\Log\Test\LoggerInterfaceTest: An abstract test class you extend to validate your custom logger implementation against the PSR-3 spec.First use case: Write a unit test for your own PSR-3 logger. Extend LoggerInterfaceTest, implement getLogger() to return your logger instance, and run the inherited tests to catch spec violations.
LoggerInterfaceTest and implement the abstract getLogger() method to return your logger. The test suite runs PSR-3 compliance checks—including message formatting, context handling, and level validation.TestLogger to capture log output in tests instead of relying on external handlers. Example:
$logger = new TestLogger();
$logger->warning('User login failed', ['user_id' => 123]);
$this->assertTrue($logger->hasRecord('warning'));
$this->assertEquals(123, $logger->getLastRecord()['context']['user_id']);
TestLogger supports optional PSR-3-style placeholder interpolation. Enable it via constructor flag (new TestLogger(interpolate: true)), then assert against the interpolated message key in records.fig/log-test to ^1.1 for PHP 8.0+ projects using psr/log ^2 or ^3. Use ^1.0 only if maintaining legacy PHP 7.4 support.context array accepts mixed[], and level is also mixed (not just string|int). This reflects real-world usage but requires type-aware assertions in tests.hasRecord() quirks: This method only checks presence of any log record—no guarantees that level, message, or context keys exist in the record array. Avoid expecting fixed structure.psr/log 1.x already included these test utilities, but they were removed in 2.x+. fig/log-test re-introduces them for 2.x/3.x. Confusingly, Composer installs fig/log-test 1.0 for psr/log 1.x, but that version is effectively empty—it just re-exports classes already in psr/log.string|int|LogLevel::XX) but double-check method signatures in your tests.TestLogger is not a drop-in replacement for production logging—it bypasses handlers entirely. Use it only in tests to assert that and how logs were called, not how they were handled.psr/log 1.x to 2.x/3.x, fig/log-test ensures continuity of your PSR-3 tests without rewrite. Just update require-dev and ensure psr/log version is compatible per the package’s version matrix.How can I help you explore Laravel packages today?