eventjet / test-double
Reusable PSR-compliant test doubles for HTTP clients, loggers, and SOAP clients
1.9.1
2026-03-10 13:31 UTC
Requires
- php: >=8.3
- ext-soap: *
- psr/http-client: ^1.0
- psr/http-message: ^2.0
- psr/log: ^3.0
Requires (Dev)
- eventjet/coding-standard: ^3.12
- guzzlehttp/psr7: ^2.7
- infection/infection: ^0.31.9
- maglnet/composer-require-checker: ^4.16
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^12.1
- psalm/plugin-phpunit: ^0.19.5
- vimeo/psalm: ^6.11
- dev-master
- 1.9.1
- 1.9.0
- 1.8.0
- 1.7.0
- 1.6.0
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.0
- v1.1.0
- v1.0.0
- dev-worktree-logger-context-value
- dev-dependabot/composer/infection/infection-tw-0.31.9or-tw-0.32.0
- dev-dependabot/github_actions/actions/checkout-6
- dev-dependabot/github_actions/actions/upload-artifact-7
- dev-dependabot/github_actions/actions/cache-5
- dev-dependabot/github_actions/actions/download-artifact-8
This package is auto-updated.
Last update: 2026-03-11 08:20:13 UTC
README
Reusable PSR-compliant test doubles for PHP — drop-in fakes for HTTP clients, loggers, and SOAP clients with a fluent matcher API and descriptive failure messages.
Requirements
- PHP 8.3+
ext-soap(only required when usingTestSoapClient)
Installation
composer require --dev eventjet/test-double
Test Doubles
| Class | Implements | Documentation |
|---|---|---|
TestLogger |
PSR-3 LoggerInterface |
doc/TestLogger.md |
TestHttpClient |
PSR-18 ClientInterface |
doc/TestHttpClient.md |
TestSoapClient |
Custom SOAP client | doc/TestSoapClient.md |
Reusable matchers (Str::regex(), Val::eq()) are documented in doc/Matchers.md.
Quick Start
TestLogger
use Eventjet\TestDouble\TestLogger; use PHPUnit\Framework\TestCase; use Psr\Log\LogLevel; final class MyServiceTest extends TestCase { public function testLogsWarningOnFailure(): void { $logger = new TestLogger(); $service = new MyService($logger); $service->doSomething(); $result = $logger->once( TestLogger::and( TestLogger::level(LogLevel::WARNING), TestLogger::message('Operation failed') ) ); self::assertTrue($result); } }
TestHttpClient
use Eventjet\TestDouble\TestHttpClient; use GuzzleHttp\Psr7\HttpFactory; use PHPUnit\Framework\TestCase; final class MyApiClientTest extends TestCase { public function testFetchesUser(): void { $factory = new HttpFactory(); $httpClient = new TestHttpClient(); $httpClient->map( TestHttpClient::path('/api/users/1'), $factory->createResponse(200)->withBody( $factory->createStream('{"id":1,"name":"John"}') ) ); $apiClient = new MyApiClient($httpClient); $user = $apiClient->getUser(1); self::assertSame('John', $user->name); } }
License
MIT — see LICENSE.