Download the PHP package timacdonald/log-fake without Composer
On this page you can find all versions of the php package timacdonald/log-fake. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package log-fake
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:
Basic usage
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.
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.
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()
assertLoggedTimes()
assertNotLogged()
assertNothingLogged()
assertWasForgotten()
assertWasForgottenTimes()
assertWasNotForgotten()
assertChannelIsCurrentlyForgotten()
assertCurrentContext()
assertLogged()
Assert that a log was created.
Can be called on
- [x] Facade base (default channel)
- [x] Channels
- [x] Stacks
Example tests
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
assertNotLogged()
Assert that a log was never created.
Can be called on
- [x] Facade base (default channel)
- [x] Channels
- [x] Stacks
Example tests
assertNothingLogged()
Assert that no logs were created.
Can be called on
- [x] Facade base (default channel)
- [x] Channels
- [x] Stacks
Example tests
assertWasForgotten()
Assert that the channel was forgotten at least one time.
Can be called on
- [x] Facade base (default channel)
- [x] Channels
- [ ] Stacks
Example tests
assertWasForgottenTimes()
Assert that the channel was forgotten a specific number of times.
Can be called on
- [x] Facade base (default channel)
- [x] Channels
- [ ] Stacks
Example tests
assertWasNotForgotten()
Assert that the channel was not forgotten.
Can be called on
- [x] Facade base (default channel)
- [x] Channels
- [ ] Stacks
Example tests
assertChannelIsCurrentlyForgotten()
Assert that a channel is currently forgotten. This is distinct from asserting that a channel was forgotten.
Can be called on
- [x] Facade base ~(default channel)~
- [ ] Channels
- [ ] Stacks
Example tests
assertCurrentContext()
Assert that the channel currently has the specified context. It is possible to provide the expected context as an array or alternatively you can provide a truth-test closure to check the current context.
Can be called on
- [x] Facade base (default channel)
- [x] Channels
- [ ] Stacks
Example tests
assertHasSharedContext()
Assert that the Log manager currently has the given shared context. It is possible to provide the expected context as an array or alternatively you can provide a truth-test closure to check the current context.
Can be called on
- [x] Facade base (default channel)
- [ ] Channels
- [ ] Stacks
Example tests
Inspection
Sometimes when debugging tests it's useful to be able to take a peek at the messages that have been logged. There are a couple of helpers to assist with this.
dump()
Dumps all the logs in the channel. You can also pass a truth-based closure to filter the logs that are dumped.
Can be called on
- [x] Facade base (default channel)
- [x] Channels
- [x] Stacks
dd()
The same as dump
, but also ends the execution.
dumpAll()
Dumps the logs for all channels. Also accepts a truth-test closure to filter any logs.
Can be called on
- [x] Facade base ~(default channel)~
- [ ] Channels
- [ ] Stacks
Example usage
ddAll()
The same as dumpAll()
, but also ends the execution.
Other APIs
logs()
Get a collection of all log entries from a channel or stack.
Can be called on
- [x] Facade base (default channel)
- [x] Channels
- [x] Stacks
Example usage
allLogs()
Similar to logs()
, except that it is called on the Facade base and returns a collection of logs from all the channels and stacks.
Can be called on
- [x] Facade base ~(default channel)~
- [ ] Channels
- [ ] Stacks
Example usage
Credits
- Tim MacDonald
- All Contributors
And a special (vegi) thanks to Caneco for the logo ✨
Thanksware
You are free to use this package, but I ask that you reach out to someone (not me) who has previously, or is currently, maintaining or contributing to an open source library you are using in your project and thank them for their work. Consider your entire tech stack: packages, frameworks, languages, databases, operating systems, frontend, backend, etc.
All versions of log-fake with dependencies
illuminate/collections Version ^10.0 || ^11.0
illuminate/contracts Version ^10.0 || ^11.0
illuminate/log Version ^10.0 || ^11.0
illuminate/support Version ^10.0 || ^11.0
phpunit/phpunit Version ^10.0 || ^11.0
psr/log Version ^1.0 || ^2.0 || ^3.0
symfony/var-dumper Version ^6.0 || ^7.0