Download the PHP package wmde/psr-log-test-doubles without Composer
On this page you can find all versions of the php package wmde/psr-log-test-doubles. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wmde/psr-log-test-doubles
More information about wmde/psr-log-test-doubles
Files in wmde/psr-log-test-doubles
Package psr-log-test-doubles
Short Description Test Doubles for the PSR-3 Logger Interface
License GPL-2.0-or-later
Homepage https://github.com/wmde/PsrLogTestDoubles
Informations about the package psr-log-test-doubles
PSR Log Test Doubles
Test Doubles for the PSR-3 Logger Interface
Motivation
In PHP world, most people create Test Doubles via PHPUnits mocking framework ($this->createMock
).
(Please beware that a PHPUnit mock really is a Test Double and not necessarily a mock.)
While this framework is often helpful, using it instead of creating your own Test Doubles comes with
some cost:
- Tools do not understand the PHPUnit magic. You will not be able to use automated refactorings such as method rename without your Test Doubles breaking. You will also get incorrect type warnings.
- When using
LoggerInterface
, your test will bind to an implementation detail: if you uselog
and provide a log level, or call a shortcut method such aserror
. - Developers need to be familiar with the mocking tool.
- Simple things such as asserting the logger got called with two messages become difficult.
Usage
This library is unit testing tool agnostic. So while these examples use PHPUnit, any testing tool can be used.
Assert the logger is called twice with expected messages
Assert the logger is called twice
Assert the message and log level of the first logger call
Release notes
3.2.0 (2022-03-28)
- Added
LogCall::isError
- Added
LogCall::withoutContext
- Added
LogCalls::filter
- Added
LogCalls::getErrors
- Added
LogCalls::map
- Added
LogCalls::withoutContexts
3.1.0 (2022-01-26)
- Added
LogCalls::getLastCall
3.0.0 (2022-01-26)
- Added support for
psr/log
2.x and 3.x - Changed minimum PHP version from PHP 7.1 to 8.0
- Added several property, parameter and return types
- Added Psalm and PHPStan CI and compliance with level 1 checks
2.2.0 (2017-05-23)
- Added
LoggerSpy::getFirstLogCall
convenience method - Changed minimum PHP version from PHP 7.0 to 7.1
2.1.0 (2017-01-17)
LogCalls
now implementsCountable
2.0.0 (2017-01-16)
LoggerSpy::getLogCalls
now returns an instance ofLogCalls
, which is a collection ofLogCall
- Added
LogCalls::getMessages
- Added
LogCalls::getFirstCall
1.1.0 (2016-11-11)
- Added
LoggerSpy::assertNoLoggingCallsWhereMade
1.0.0 (2016-10-18)
- Initial release with minimal
LoggerSpy