Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
A drop in fake logger for testing with the Laravel framework.
| Date | Stars |
|---|---|
| 2026-07-24 | 423 |
| 2026-07-25 | 423 |
| 2026-07-28 | 423 |
| 2026-07-30 | 423 |
| 2026-08-06 | 423 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
<p align="center"><img src="/art/header.png" alt="Log Fake: a Laravel package by Tim MacDonald"></p>
# Log fake for Laravel
A bunch of Laravel facades / services are able to be faked, such as the Dispatcher with `Bus::fake()`, to help with testing and assertions. This package gives you the ability to fake the logger in your app, and includes the ability to make assertions against channels, stacks, and a whole bunch more.
## Installation
You can install using [composer](https://getcomposer.org/):
```sh
composer require timacdonald/log-fake --dev
```
## Basic usage
```php
use Illuminate\Support\Facades\Log;
use TiMacDonald\Log\LogEntry;
use TiMacDonald\Log\LogFake;
public function testItLogsWhenAUserAuthenticates()
{
/*
* Test setup.
*
* In the setup of your tests, you can call the following `bind` helper,
* which will switch out the underlying log driver with the fake.
*/
LogFake::bind();
/*
* Application implementation.
*
* In your application's implementation, you then utilise the logger, as you
* normally would.
*/
Log::info('User logged in.', ['user_id' => $user->id]);
/*
* Test assertions.
*
* Finally you can make assertions against the log channels, stacks, etc. to
* ensure the expected logging occurred in your implementation.
*/
Log::assertLogged(fn (LogEntry $log) =>
$log->level === 'info'
&& $log->message === 'User logged in.'
&& $log->context === ['user_id' => 5]
);
}
```
## Channels
If you are logging to a specific channel (i.e. not the default channel) in your app, you need to also prefix your assertions in the same manner.
```php
public function testItLogsWhenAUserAuthenticates()
{
// setup...
LogFake::bind();
// implementation...
Log::channel('slack')->info('User logged in.', ['user_id' => $user->id]);
// assertions...
Log::channel('slack')->assertLogged(
fn (LogEntry $log) => $log->message === 'User logged in.'
);
}
```
## Stacks
If you are logging to a stack in your app, like with channels, you will need to prefix your assertions. Note that the order of the stack does not matter.
```php
public function testItLogsWhenAUserAuthenticates()
{
// setup...
LogFake::bind();
// implementation...
Log::stack(['stderr', 'single'])->info('User logged in.', ['user_id' => $user->id]);
// assertions...
Log::stack(['stderr', 'single'])->assertLogged(
fn (LogEntry $log) => $log->message === 'User logged in.'
);
}
```
That's it really. Now let's dig into the available assertions to improve your experience testing your applications logging.
## Available assertions
Remember that all assertions are relative to the channel or stack as shown above.
- [`assertLogged()`](#assertlogged)
- [`assertLoggedTimes()`](#assertloggedtimes)
- [`assertNotLogged()`](#assertnotlogged)
- [`assertNothingLogged()`](#assertnothinglogged)
- [`assertWasForgotten()`](#assertwasforgotten)
- [`assertWasForgottenTimes()`](#assertwasforgottentimes)
- [`assertWasNotForgotten()`](#assertwasnotforgotten)
- [`assertChannelIsCurrentlyForgotten()`](#assertchanneliscurrentlyforgotten)
- [`assertCurrentContext()`](#assertcurrentcontext)
### assertLogged()
Assert that a log was created.
#### Can be called on
- [x] Facade base (default channel)
- [x] Channels
- [x] Stacks
#### Example tests
```php
/*
* implementation...
*/
Log::info('User logged in.');
/*
* assertions...
*/
Log::assertLogged(
fn (LogEntry $log) => $log->message === 'User logged in.'
); // ✅
Log::assertLogged(
fn (LogEntry $log) => $log->level === 'critical'
); // ❌ as log had a level of `info`.
```
### assertLoggedTimes()
Assert that a log was created a specific number of times.
#### Can be called on
- [x] Facade base (default channel)
- [x] Channels
- [x] Stacks
#### Example tests
```php
/*
* implementation...
*/
Log::info('Stripe request initiated.');Excerpt of 12,601 characters
Read on GitHubWould you bet a product on this? Bounded 0–100 and slow moving.
matched fp:ae9af1ee82652869, topic:testing