PHPackages                             mileschou/slim-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. mileschou/slim-test

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

mileschou/slim-test
===================

A simple test helper for Slim Framework 3

v0.0.1(3y ago)79.4k↓50%2MITPHPPHP ^7.2 | ^8.0

Since Jun 24Pushed 3y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

Slim Test
=========

[](#slim-test)

[![Latest Stable Version](https://camo.githubusercontent.com/d6a1b8246acc3794dfe9eae6e551d4aa498a9676b5acb2b1ef192b25f200c3ef/68747470733a2f2f706f7365722e707567782e6f72672f6d696c657363686f752f736c696d2d746573742f762f737461626c65)](https://packagist.org/packages/mileschou/slim-test)[![Build Status](https://camo.githubusercontent.com/50798e18ea51b5b9d3112a3e315a02c16a0ab5227b1a95f90be7859e16eb939c/68747470733a2f2f7472617669732d63692e6f72672f4d696c657343686f752f736c696d2d746573742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/MilesChou/slim-test)[![codecov](https://camo.githubusercontent.com/67ecf5077bba8e702ec49eb756a03d8e2c82f90aea3d0839a93312d1974ece62/68747470733a2f2f636f6465636f762e696f2f67682f4d696c657343686f752f736c696d2d746573742f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/MilesChou/slim-test)[![License](https://camo.githubusercontent.com/fc772fccfd84e66db294a54f2f02dee2baa9cbd858686341c2c7ddf56f73ceee/68747470733a2f2f706f7365722e707567782e6f72672f6d696c657363686f752f736c696d2d746573742f6c6963656e7365)](https://packagist.org/packages/mileschou/slim-test)

A simple test helper for [Slim Framework 3](http://www.slimframework.com/)

The repository has some example in `tests` folder. [app.php](/app.php) is a definition use simple Slim router, [SlimCaseTest.php](/tests/SlimCaseTest.php) is testing for `SlimCase` class, and [ClientTest.php](/tests/ClientTest.php) is testing for `Client` class. You can use `Client` If you want to use PHPUnit style to write test, or use `SlimCase` in Codeception style.

Installation with Composer
--------------------------

[](#installation-with-composer)

```
$ composer require --dev mileschou/slim-test

```

Using object in PHPUnit
-----------------------

[](#using-object-in-phpunit)

First, prepare your Slim App in test code and pass to `SlimCase` constructor.

```
use MilesChou\Slim\Test\SlimCase;

class SlimAppTest extends PHPUnit_Framework_TestCase
{
    public function setUp()
    {
        $app = require 'path/to/app.php';
        $this->slimCase = new SlimCase($app);
    }
}
```

Now, you can use [Codeception Style](http://codeception.com/docs/modules/REST) to make assertion.

```
public function testSeeResponseOk()
{
    // Arrange
    $url = '/will/return/ok';

    // Act
    $this->slimCase->sendGET($url);

    // Assert
    $this->slimCase->seeResponseOk();
}
```

The visibility of `Client` object in `SlimCase` is public. That means you can use `Client` like

```
$this->slimCase->client->get($url);
```

> It's unsafe to access client object **directly**. The visibility will modify to `private` in the future.

Using trait in PHPUnit
----------------------

[](#using-trait-in-phpunit)

You can use `ClientTrait` or `SlimCaseTrait` in PHPUnit, too. Here is an example:

```
use MilesChou\Slim\Test\SlimCaseTrait;

class SlimAppTest extends PHPUnit_Framework_TestCase
{
    use SlimCaseTrait;

    public function setUp()
    {
        $app = require 'path/to/app.php';
        $this->setSlimApp($app);
    }

    public function tearDown()
    {
        $this->setSlimApp(null);
    }

    public function testSeeResponseOk()
    {
        // Arrange
        $url = '/will/return/ok';

        // Act
        $this->sendGET($url);

        // Assert
        $this->seeResponseOk();
    }
}
```

Using in Behat
--------------

[](#using-in-behat)

It's easy to using Slim Test in [Behat](http://docs.behat.org/). For example, I have a feature file

```
# features/app.feature
Feature: an example testing use behat

  Scenario: Test assert response is okay
    Given a route named "/will/return/ok"
    When visit "/will/return/ok"
    Then I should see response okay
```

And implement context file easily

```
// features/bootstrap/FeatureContext.php
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use MilesChou\Slim\Test\SlimCaseTrait;

class FeatureContext implements Context, SnippetAcceptingContext
{
    use SlimCaseTrait;

    public function __construct()
    {
        // bootstrap your slim app
        $app = require __DIR__ . '/../../app.php';
        $this->setSlimApp($app);
    }

    /** @Given a route named :url */
    public function aRouteNamed($url) { /** Do nothing */ }

    /** @When visit :url */
    public function visit($url)
    {
        $this->sendGET($url);
    }

    /** @Then I should see response okay */
    public function iShouldSeeResponseOkay()
    {
        $this->seeResponseOk();
    }
}
```

Tests
-----

[](#tests)

Execute all test suite use [PHPUnit](https://phpunit.de/) and [Behat](http://docs.behat.org/)

```
$ php vendor/bin/phpunit
$ php vendor/bin/behat

```

You can use composer scripts, too

```
$ composer test

```

Run PHP built-in server if you want to check HTTP response via browser

```
$ php -S 0.0.0.0:8080 -t public

```

License
-------

[](#license)

The Slim Test is licensed under the MIT license. See [License File](LICENSE) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity42

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

1424d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/20872dcc4b888075f03819d5470db8198ffcc5f9edb791aba5f007e34355a6c9?d=identicon)[MilesChou](/maintainers/MilesChou)

---

Top Contributors

[![MilesChou](https://avatars.githubusercontent.com/u/1258752?v=4)](https://github.com/MilesChou "MilesChou (49 commits)")

---

Tags

testingslim

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/mileschou-slim-test/health.svg)

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

###  Alternatives

[behat/mink

Browser controller/emulator abstraction for PHP

1.6k86.1M606](/packages/behat-mink)[symfony/panther

A browser testing and web scraping library for PHP and Symfony.

3.1k14.7M96](/packages/symfony-panther)[behat/mink-browserkit-driver

Symfony2 BrowserKit driver for Mink framework

54562.0M318](/packages/behat-mink-browserkit-driver)[nunomaduro/laravel-mojito

A lightweight package for testing Laravel views.

368435.5k11](/packages/nunomaduro-laravel-mojito)[laracasts/integrated

Simple, intuitive integration testing with PHPUnit.

479206.9k2](/packages/laracasts-integrated)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2021.0M277](/packages/drupal-core-dev)

PHPackages © 2026

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