Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: composer
directory: /
schedule:
interval: weekly

- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
130 changes: 125 additions & 5 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,128 @@
name: PHP
name: CI

on: [pull_request]
on:
pull_request:
push:
branches: [master]
Comment thread
MidnightDesign marked this conversation as resolved.

jobs:
qa:
uses: eventjet/ci/.github/workflows/php.yml@main
secrets: inherit
deps:
name: Dependency Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: soap
- uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- run: composer install --prefer-dist --no-progress
- run: composer check-deps
Comment thread
MidnightDesign marked this conversation as resolved.

cs:
name: Code Style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: soap
- uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- run: composer install --prefer-dist --no-progress
- run: composer cs-check
Comment thread
MidnightDesign marked this conversation as resolved.

psalm:
name: Psalm
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: soap
- uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- run: composer install --prefer-dist --no-progress
- run: composer psalm

phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: soap
- uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- run: composer install --prefer-dist --no-progress
- run: composer phpstan

tests:
name: Tests (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.3', '8.4', '8.5']
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: soap, pcov
coverage: pcov
- uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
restore-keys: ${{ runner.os }}-php${{ matrix.php }}-composer-
- run: composer install --prefer-dist --no-progress
- name: Run tests
run: composer phpunit
if: matrix.php != '8.3'
- name: Run tests with coverage
run: composer phpunit -- --coverage-xml=coverage --log-junit=coverage/junit.xml
if: matrix.php == '8.3'
- uses: actions/upload-artifact@v4
if: matrix.php == '8.3'
with:
name: coverage
path: coverage/

mutation:
name: Mutation Testing
runs-on: ubuntu-latest
needs: tests
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: soap
- uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php8.3-composer-${{ hashFiles('composer.json') }}
restore-keys: ${{ runner.os }}-php8.3-composer-
- run: composer install --prefer-dist --no-progress
- uses: actions/download-artifact@v4
with:
name: coverage
path: coverage/
- run: composer infection -- --coverage=coverage --skip-initial-tests
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Datascroll Eventsupport GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# eventjet/test-double

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 using `TestSoapClient`)

Comment thread
MidnightDesign marked this conversation as resolved.
## Installation

```bash
composer require --dev eventjet/test-double
```

## Test Doubles

| Class | Implements | Documentation |
|---|---|---|
| `TestLogger` | PSR-3 `LoggerInterface` | [doc/TestLogger.md](doc/TestLogger.md) |
| `TestHttpClient` | PSR-18 `ClientInterface` | [doc/TestHttpClient.md](doc/TestHttpClient.md) |
| `TestSoapClient` | Custom SOAP client | [doc/TestSoapClient.md](doc/TestSoapClient.md) |

Reusable matchers (`Str::regex()`, `Val::eq()`) are documented in [doc/Matchers.md](doc/Matchers.md).

## Quick Start

### TestLogger

```php
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

```php
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](LICENSE).
11 changes: 3 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "eventjet/test-double",
"type": "library",
"description": "",
"license": "proprietary",
"description": "Reusable PSR-compliant test doubles for HTTP clients, loggers, and SOAP clients",
"keywords": ["testing", "test-double", "mock", "stub", "psr-3", "psr-18", "http-client", "logger", "phpunit"],
"license": "MIT",
"require": {
"php": ">=8.3",
"ext-soap": "*",
Expand Down Expand Up @@ -42,12 +43,6 @@
"Eventjet\\Test\\Unit\\TestDouble\\": "tests/unit"
}
},
"repositories": [
{
"type": "composer",
"url": "https://pack.eventjet.at/"
}
],
"minimum-stability": "stable",
"scripts": {
"check": [
Expand Down
Loading