PHPackages                             meritum/http-testing - 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. meritum/http-testing

ActiveLibrary

meritum/http-testing
====================

HTTP request/response testing helpers for the Meritum ecosystem

0.1.0(1mo ago)04↓75%MITPHPPHP ^8.4CI passing

Since Jul 16Pushed 1mo agoCompare

[ Source](https://github.com/MeritumIO/http-testing)[ Packagist](https://packagist.org/packages/meritum/http-testing)[ RSS](/packages/meritum-http-testing/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

meritum/http-testing
====================

[](#meritumhttp-testing)

HTTP request/response testing helpers for the Meritum ecosystem — builds a PSR-7 request, drives it through any PSR-15 `RequestHandlerInterface`, and wraps the resulting response for assertions. No dependency on `meritum/testing` or `meritum/http` — it works against the standard PSR-7/PSR-15 interfaces, so any consumer's app kernel qualifies as long as it implements `RequestHandlerInterface`. Retrieving that handler from wherever a project stores it (a test kernel, a bare property, etc.) is the consuming project's own responsibility, not this package's.

Requirements
------------

[](#requirements)

- PHP 8.4+
- `phpunit/phpunit` ^11.0
- `psr/http-message` ^1.1
- `psr/http-server-handler` ^1.0
- `laminas/laminas-diactoros` ^3.0

Installation
------------

[](#installation)

```
composer require meritum/http-testing
```

Usage
-----

[](#usage)

### `HttpTestingTrait`

[](#httptestingtrait)

The usual way to use this package: add the trait to a PHPUnit test case and implement `getRequestHandler()` to return whatever `RequestHandlerInterface` your app kernel exposes — however you obtain it is up to you:

```
use PHPUnit\Framework\TestCase;
use Psr\Http\Server\RequestHandlerInterface;
use Meritum\HttpTesting\HttpTestingTrait;

abstract class ApiTestCase extends TestCase
{
    use HttpTestingTrait;

    protected function getRequestHandler(): RequestHandlerInterface
    {
        return $this->kernel->get(HttpKernelInterface::class); // however your project stores it
    }
}
```

Every test then gets `get()`, `post()`, `put()`, `patch()`, `delete()`, `head()`, and `options()`, each returning a `TestResponse`:

```
final class PostsTest extends ApiTestCase
{
    public function test_it_creates_a_post(): void
    {
        $this->post('/posts', ['title' => 'Hello'])
             ->assertCreated()
             ->assertAttributeEquals('data.title', 'Hello');
    }
}
```

`getRequestHandler()` is only called once per test — the trait caches the `Client` it builds around the returned handler, so it's safe (and expected) to resolve the handler from a kernel or container each time without worrying about rebuilding it per request.

### `Client`

[](#client)

The lower-level piece the trait is built on, for anyone not using PHPUnit test cases directly:

```
use Meritum\HttpTesting\Client;

$client = new Client($handler); // any Psr\Http\Server\RequestHandlerInterface

$response = $client->request('POST', '/posts', ['title' => 'Hello']);
```

For `POST`/`PUT`/`PATCH`, the parsed body is JSON-encoded and written directly into the request's body stream (not set as PSR-7's `parsedBody`) — this matches how most middleware pipelines actually read the request body, rather than relying on `parsedBody` being populated. `Content-Type: application/json` is set by default for those methods unless a header already provides one.

### `TestResponse`

[](#testresponse)

Wraps whatever `ResponseInterface` comes back, with chainable assertions:

- `assertStatus(int $status)` plus shortcuts for the common codes — `assertOk`, `assertCreated`, `assertAccepted`, `assertNoContent`, `assertMovedPermanently`, `assertFound`, `assertBadRequest`, `assertUnauthorized`, `assertForbidden`, `assertNotFound`, `assertMethodNotAllowed`, `assertNotAcceptable`, `assertRequestTimeout`, `assertConflict`, `assertGone`, `assertUnsupportedMediaType`, `assertUnprocessableContent`, `assertTooManyRequests`, `assertInternalServerError`, `assertBadGateway`, `assertServiceUnavailable`, `assertGatewayTimeout`
- `assertHeader(string $name, string $value)`
- `assertBodyEquals(array $expected)` — loose equality against the full decoded JSON body
- `assertAttributeExists(string $path)` / `assertAttributeType(string $path, string $type)` / `assertAttributeEquals(string $path, mixed $value)` — dot-path lookups resolved from the response body root (e.g. `'data.name'`, not assumed to start under any particular key), so these work equally well against a success envelope or an error envelope
- `getResponse(): ResponseInterface` / `getResponseBody(): array` — escape hatches for anything not covered by the assertion methods above

Every assertion method returns `$this`, so they chain:

```
$this->get('/posts/1')
     ->assertOk()
     ->assertHeader('Content-Type', 'application/json')
     ->assertAttributeEquals('data.id', '1');
```

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance90

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

45d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c8147ce1d901e9fa2ec95d6408e5862025211f9ae60131e41fb115a5a0916ce4?d=identicon)[georgeff](/maintainers/georgeff)

---

Top Contributors

[![MikeGeorgeff](https://avatars.githubusercontent.com/u/6169468?v=4)](https://github.com/MikeGeorgeff "MikeGeorgeff (1 commits)")

###  Code Quality

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/meritum-http-testing/health.svg)

```
[![Health](https://phpackages.com/badges/meritum-http-testing/health.svg)](https://phpackages.com/packages/meritum-http-testing)
```

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.9k20.4M1.9k](/packages/cakephp-cakephp)[tempest/framework

The PHP framework that gets out of your way.

2.3k42.4k21](/packages/tempest-framework)[bref/bref

Bref is a framework to write and deploy serverless PHP applications on AWS Lambda.

3.4k11.3M78](/packages/bref-bref)[cakephp/authentication

Authentication plugin for CakePHP

1184.6M126](/packages/cakephp-authentication)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[flarum/core

Delightfully simple forum software.

271.5M2.6k](/packages/flarum-core)

PHPackages © 2026

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