PHPackages                             jeroen/psr-log-test-doubles - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. jeroen/psr-log-test-doubles

ActiveLibrary[Testing &amp; Quality](/categories/testing)

jeroen/psr-log-test-doubles
===========================

Test Doubles for the PSR-3 Logger Interface

3.2.0(4y ago)277.0k↑28.6%[1 PRs](https://github.com/JeroenDeDauw/PsrLogTestDoubles/pulls)8GPL-2.0-or-laterPHPPHP &gt;=8.0

Since Oct 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/JeroenDeDauw/PsrLogTestDoubles)[ Packagist](https://packagist.org/packages/jeroen/psr-log-test-doubles)[ Docs](https://github.com/JeroenDeDauw/PsrLogTestDoubles)[ GitHub Sponsors](https://github.com/JeroenDeDauw)[ RSS](/packages/jeroen-psr-log-test-doubles/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (10)Used By (8)

PSR Log Test Doubles
====================

[](#psr-log-test-doubles)

[![Build Status](https://camo.githubusercontent.com/d1c944932633e93ed4be4c2b1ce9c3be4ee71a9b694f93cbdc9b60d847dce12b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4a65726f656e4465446175772f5073724c6f6754657374446f75626c65732f63692e796d6c3f6272616e63683d6d6173746572)](https://github.com/JeroenDeDauw/PsrLogTestDoubles/actions?query=workflow%3ACI)[![Type Coverage](https://camo.githubusercontent.com/9db835f8bc0922ff015fb2f75cec3ba38340650473df0b2023f70615ae3d0866/68747470733a2f2f73686570686572642e6465762f6769746875622f4a65726f656e4465446175772f5073724c6f6754657374446f75626c65732f636f7665726167652e737667)](https://shepherd.dev/github/JeroenDeDauw/PsrLogTestDoubles)[![Psalm level](https://camo.githubusercontent.com/0f79329201aa41fa21ad9641ae613fab9994d840d732b09a49eb9de003c50eab/68747470733a2f2f73686570686572642e6465762f6769746875622f4a65726f656e4465446175772f5073724c6f6754657374446f75626c65732f6c6576656c2e737667)](psalm.xml)[![codecov](https://camo.githubusercontent.com/81cbd5e63a77b953064757b4e858629178c1e6a5babc4f9c103e71791b738413/68747470733a2f2f636f6465636f762e696f2f67682f4a65726f656e4465446175772f5073724c6f6754657374446f75626c65732f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d476e4f4733464631365a)](https://codecov.io/gh/JeroenDeDauw/PsrLogTestDoubles)[![Latest Stable Version](https://camo.githubusercontent.com/70a721182b6ba9eeebe67659b1b0998cfde33ab837dd9a3cadadc2e00bfa8cb8/68747470733a2f2f706f7365722e707567782e6f72672f6a65726f656e2f7073722d6c6f672d746573742d646f75626c65732f762f737461626c65)](https://packagist.org/packages/jeroen/psr-log-test-doubles)[![Download count](https://camo.githubusercontent.com/e23a01c53d75e68ecfc2073695fbca17dc035396168716f868aaf6eb9c2e93c7/68747470733a2f2f706f7365722e707567782e6f72672f6a65726f656e2f7073722d6c6f672d746573742d646f75626c65732f646f776e6c6f616473)](https://packagist.org/packages/jeroen/psr-log-test-doubles)

[Test Doubles](https://en.wikipedia.org/wiki/Test_double) for the [PSR-3 Logger Interface](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md)

Composer/Packagist: [`jeroen/psr-log-test-doubles`](https://packagist.org/packages/jeroen/psr-log-test-doubles)

Motivation
----------

[](#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](https://www.entropywins.wtf/blog/2016/05/13/5-ways-to-write-better-mocks/) 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 use `log` and provide a log level, or call a shortcut method such as `error`.
- Developers need to be familiar with the mocking tool.
- Simple things such as asserting the logger got called with two messages become difficult.

Usage
-----

[](#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**

```
public function testWhenStuffIsDone_loggerGetsCalled() {
    $logger = new LoggerSpy();

    $serviceToTest = new ServiceToTest( $logger /*, other dependencies */ );
    $serviceToTest->doStuff( /**/ );

    $this->assertSame(
        [ 'First message', 'Second message' ],
        $logger->getLogCalls()->getMessages()
    );
}
```

**Assert the logger is called twice**

```
$this->assertCount( 2, $logger->getLogCalls() );
```

**Assert the message and log level of the first logger call**

```
$firstLogCall = $logger->getFirstLogCall();

$this->assertSame( 'First message', $firstLogCall->getMessage() );
$this->assertSame( LogLevel::ERROR, $firstLogCall->getLevel() );
```

Release notes
-------------

[](#release-notes)

### 3.2.0 (2022-03-28)

[](#320-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)

[](#310-2022-01-26)

- Added `LogCalls::getLastCall`

### 3.0.0 (2022-01-26)

[](#300-2022-01-26)

- Added support for `psr/log` 2.x and 3.x
- `LoggerSpy` only supports `psr/log` 2.x and 3.x. Added `LegacyLoggerSpy` for `psr/log` 1.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)

[](#220-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)

[](#210-2017-01-17)

- `LogCalls` now implements `Countable`

### 2.0.0 (2017-01-16)

[](#200-2017-01-16)

- `LoggerSpy::getLogCalls` now returns an instance of `LogCalls`, which is a collection of `LogCall`
- Added `LogCalls::getMessages`
- Added `LogCalls::getFirstCall`

### 1.1.0 (2016-11-11)

[](#110-2016-11-11)

- Added `LoggerSpy::assertNoLoggingCallsWhereMade`

### 1.0.0 (2016-10-18)

[](#100-2016-10-18)

- Initial release with minimal `LoggerSpy`

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 90.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~283 days

Recently: every ~474 days

Total

8

Last Release

1513d ago

Major Versions

1.1.0 → 2.0.02017-01-16

2.2.0 → 3.0.02022-01-25

PHP version history (3 changes)1.0.0PHP &gt;=7.0

2.2.0PHP &gt;=7.1

3.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/451bd4039d530fed8f9c3da91bfa519233a397d2182cdfdcad700f6cfea19b7f?d=identicon)[Jeroen De Dauw](/maintainers/Jeroen%20De%20Dauw)

---

Top Contributors

[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (68 commits)")[![gbirke](https://avatars.githubusercontent.com/u/223326?v=4)](https://github.com/gbirke "gbirke (6 commits)")[![manicki](https://avatars.githubusercontent.com/u/3524114?v=4)](https://github.com/manicki "manicki (1 commits)")

---

Tags

psrlogpsr-3testFixturefixturesmocktest doublespytest-doublesmocksspieslogger spyLoggerSpy

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jeroen-psr-log-test-doubles/health.svg)

```
[![Health](https://phpackages.com/badges/jeroen-psr-log-test-doubles/health.svg)](https://phpackages.com/packages/jeroen-psr-log-test-doubles)
```

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k497.0M23.6k](/packages/mockery-mockery)[php-mock/php-mock

PHP-Mock can mock built-in PHP functions (e.g. time()). PHP-Mock relies on PHP's namespace fallback policy. No further extension is needed.

36918.1M98](/packages/php-mock-php-mock)[phake/phake

The Phake mock testing library

4758.0M324](/packages/phake-phake)[colinodell/psr-testlogger

PSR-3 compliant test logger based on psr/log v1's, but compatible with v2 and v3 too!

1712.1M47](/packages/colinodell-psr-testlogger)[php-mock/php-mock-phpunit

Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespace fallback policy. No further extension is needed.

1718.2M399](/packages/php-mock-php-mock-phpunit)[php-mock/php-mock-mockery

Mock built-in PHP functions (e.g. time()) with Mockery. This package relies on PHP's namespace fallback policy. No further extension is needed.

392.1M96](/packages/php-mock-php-mock-mockery)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
