PHPackages                             zfegg/expressive-test - 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. zfegg/expressive-test

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

zfegg/expressive-test
=====================

Zend Expressive abstract test case for PHPUnit

0.7.1(1y ago)0896↓100%3MITPHPPHP &gt;=8.1

Since Mar 23Pushed 1y ago3 watchersCompare

[ Source](https://github.com/zfegg/expressive-test)[ Packagist](https://packagist.org/packages/zfegg/expressive-test)[ RSS](/packages/zfegg-expressive-test/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (15)Used By (3)

Mezzio (Expressive) handler test
================================

[](#mezzio-expressive-handler-test)

[![GitHub Actions: Run tests](https://github.com/zfegg/expressive-test/workflows/qa/badge.svg)](https://github.com/zfegg/expressive-test/actions?query=workflow%3A%22qa%22)[![Coverage Status](https://camo.githubusercontent.com/6992d346d23c42174457f839cabe38f5410509bbe7a0f6cd5f138086518644f7/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7a666567672f657870726573736976652d746573742f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/zfegg/expressive-test?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/a61cbba5508ebb6568b6aaaf2aefe140c5c29fbbd3d391975a6ef3e6d89f3e8b/68747470733a2f2f706f7365722e707567782e6f72672f7a666567672f657870726573736976652d746573742f762f737461626c652e706e67)](https://packagist.org/packages/zfegg/expressive-test)

Using test tools like Laravel in Mezzio (Expressive) unit tests.

使用类似Laravel的测试工具在 Mezzio (Expressive) 的单元测试中.

Installation / 安装使用
-------------------

[](#installation--安装使用)

Install via composer.

```
composer require zfegg/expressive-test --dev
```

Usage / 使用
----------

[](#usage--使用)

### `runApp(...)` in test.

[](#runapp-in-test)

```
use Psr\Http\Message\ResponseInterface;
use Zfegg\ExpressiveTest\AbstractActionTestCase;

class HomePageTest extends AbstractActionTestCase {

    public function testHome() {
        $response = $this->runApp(
            'POST',
            '/?test=1',
            ['body' => '2'],
            ['HTTP_CONTENT_TYPE' => 'application/json'],
            '{"a":"b"}',
            ['cookie' => '3']
        );

        $this->assertInstanceOf(ResponseInterface::class, $response);
    }

    public function testPassMiddlewareOrMockService() {

        $this->container->setService('some middleware', new PassMiddleware());

        $mock = $this->createMock(SomeService::class);
        $this->container->setService('mock some service', $mock);

        $response = $this->runApp(
            'POST',
            '/?test=1',
            ['body' => '2'],
            ['HTTP_CONTENT_TYPE' => 'application/json'],
            '{"a":"b"}',
            ['cookie' => '3']
        );

        $this->assertInstanceOf(ResponseInterface::class, $response);
    }
}
```

### Simple test methods like Laravel

[](#simple-test-methods-like-laravel)

```
use Psr\Http\Message\ResponseInterface;
use Zfegg\ExpressiveTest\AbstractActionTestCase;

class HomePageTest extends AbstractActionTestCase {

    public function testHome() {
        /*
        $this->get($uri, $headers = []);
        $this->getJson($uri, $headers = []);
        $this->post($uri, $data = [], $headers = []);
        $this->postJson($uri, $data = [], $headers = []);
        $this->put($uri, $data = [], $headers = []);
        $this->putJson($uri, $data = [], $headers = []);
        $this->patch($uri, $data = [], $headers = []);
        $this->patchJson($uri, $data = [], $headers = []);
        $this->delete($uri, $data = [], $headers = []);
        $this->json($method, $uri, $data = [], $headers = []);
        $this->call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null);
        */
        $response = $this->getJson('/?test=1');
        $response->assertOk();
        $response->assertSuccessful();
    }

    public function testRedirectLogin() {
        $response = $this->getJson('/redirect');
        $response->assertRedirect('/login');
    }
}
```

### Test support methods

[](#test-support-methods)

- `get($uri, $headers = [])`
- `getJson($uri, $headers = [])`
- `post($uri, $data = [], $headers = [])`
- `postJson($uri, $data = [], $headers = [])`
- `put($uri, $data = [], $headers = [])`
- `putJson($uri, $data = [], $headers = [])`
- `patch($uri, $data = [], $headers = [])`
- `patchJson($uri, $data = [], $headers = [])`
- `delete($uri, $data = [], $headers = [])`
- `json($method, $uri, $data = [], $headers = [])`
- `call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)`

### Response assert methods

[](#response-assert-methods)

- `assertCookie`
- `assertCookieExpired`
- `assertCookieMissing`
- `assertCookieNotExpired`
- `assertCreated`
- `assertDontSee`
- `assertDontSeeText`
- `assertExactJson`
- `assertForbidden`
- `assertHeader`
- `assertHeaderMissing`
- `assertJson`
- `assertJsonCount`
- `assertJsonMessage`
- `assertJsonMissing`
- `assertJsonMissingExact`
- `assertJsonPath`
- `assertJsonStructure`
- `assertLocation`
- `assertNoContent`
- `assertNotFound`
- `assertOk`
- `assertRedirect`
- `assertSee`
- `assertSeeText`
- `assertStatus`
- `assertSuccessful`
- `assertUnauthorized`

### `PassMiddleware`

[](#passmiddleware)

For pass a middleware. As default it will pass [`ErrorHandler::class`](src/Helper/SetupApplicationTrait.php#L55).

```
use Psr\Http\Message\ResponseInterface;
use Zfegg\ExpressiveTest\AbstractActionTestCase;
use Zfegg\ExpressiveTest\PassMiddleware;

class HomePageTest extends AbstractActionTestCase {

    public function testHome() {
        // Pass a authentication middleware.
        $this->container->setService(AuthenticationMiddleware::class, PassMiddleware::class);

        $response = $this->getJson('/api/users');
        $response->assertOk();
    }
}
```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 98.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 ~189 days

Recently: every ~266 days

Total

13

Last Release

695d ago

PHP version history (3 changes)0.5.0PHP ^7.2

0.6.1PHP &gt;=7.2

0.7.0PHP &gt;=8.1

### Community

Maintainers

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

---

Top Contributors

[![Moln](https://avatars.githubusercontent.com/u/2050694?v=4)](https://github.com/Moln "Moln (78 commits)")[![dragosprotung](https://avatars.githubusercontent.com/u/1081073?v=4)](https://github.com/dragosprotung "dragosprotung (1 commits)")

---

Tags

expressive-testmezzio-testphpphpunittestlaminaszendmezzioexpressive

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/zfegg-expressive-test/health.svg)

```
[![Health](https://phpackages.com/badges/zfegg-expressive-test/health.svg)](https://phpackages.com/packages/zfegg-expressive-test)
```

###  Alternatives

[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[ta-tikoma/phpunit-architecture-test

Methods for testing application architecture

10745.9M13](/packages/ta-tikoma-phpunit-architecture-test)[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)[fr3d/swagger-assertions

Test your API requests and responses against your swagger definition

138850.9k5](/packages/fr3d-swagger-assertions)[laminas/laminas-test

Tools to facilitate integration testing of laminas-mvc applications

122.9M184](/packages/laminas-laminas-test)[facile-it/sentry-module

This module allows integration of Sentry Client into laminas and mezzio

19372.5k](/packages/facile-it-sentry-module)

PHPackages © 2026

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