Purpose Alignment: The package (timacdonald/log-fake) is a drop-in fake logger designed specifically for Laravel testing, replacing the default Monolog or Psr\Log\LoggerInterface implementations with a mockable, assertion-friendly logger (e.g., Log::shouldReceive('error')->once()).
Log::), ensuring minimal boilerplate.Key Features:
Psr\Log\LoggerInterface, ensuring compatibility with Laravel’s logging stack.shouldReceive(), assertLogged(), etc., for PHPUnit/Pest assertions (e.g., verifying log calls).['user_id' => 123]) for precise assertions.debug, error) independently.config/logging.php with the fake logger only in test environments (e.g., via phpunit.xml or Pest.php).
// config/logging.php (test environment)
'default' => env('LOG_CHANNEL', 'fake'),
'fake' => [
'driver' => 'fake',
'via' => \TimacDonald\LogFake\FakeLogger::class,
],
Log::assertLogged('error')).['user_id' => 123] vs. ['user_id' => '123']).assertLoggedWithContext() with flexible matchers.Psr\Log implementation.debug vs. error) be prioritized in assertions?Mockery or Laravel’s built-in testing helpers (e.g., expectsJob() for queues).Log::spy() patterns?assertLogged()).Log facade; requires manual PSR-3 mocking elsewhere.Log::info() checks with Log::shouldReceive('info')->once() in a single test file.phpunit.xml/Pest.php to use the fake logger by default:
<!-- phpunit.xml -->
<env name="LOG_CHANNEL" value="fake"/>
composer.json constraints.single, stack) if fake logger is the default.Log:: (e.g., spatie/laravel-logging) will transparently use the fake logger in tests.composer require --dev timacdonald/log-fake
config/logging.php.assertLoggedWithContext()).phpunit --coverage).shouldReceive() syntax.| Failure Type | Cause | Mitigation |
|---|---|---|
| False Negatives | Missing assertLogged() calls |
Enforce via custom PHPUnit traits. |
| Context Mismatches | Log context differs slightly | Use assertLoggedWithContext() with wildcards. |
| Flaky CI Tests | Environment-specific log levels | Standardize log levels in tests. |
| Test Slowdown | Excessive assertions | Optimize: Group related logs into single assertions. |
shouldReceive() and assertLogged() basics.Log:: assertions.infection to verify assertion robustness.How can I help you explore Laravel packages today?