New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

mileschou/slim-test

A simple test helper for Slim Framework 3
9,660 7

Larablocks Analysis

mileschou/slim-test works with Laravel 6 to 9 (latest release v0.0.1, Jun 24, 2022), all past end of life (the last on Feb 6, 2024): no more fixes, even for security.

Recommendation checks

Not advised

Not advised: no release or commit in over 2 years.

  • No release or commit in over 2 years
  • Supports only Laravel 6 to 9, past end of life since Feb 6, 2024
  • No release in the last 12 months (last: Jun 24, 2022)
  • 132 downloads a month (needs 10,000)
  • 7 GitHub stars (needs 100)

State

Likely abandoned
  • No release or commit in over 2 years.
  • Last stable release: Jun 24, 2022.
  • No releases in the last 12 months.
  • First released: Jun 24, 2022.
  • Monthly downloads: 132.
  • 0 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Nov 27, 2026.

Install
composer require mileschou/slim-test
Latest Version:v0.0.1
PHP:^7.2 | ^8.0
Laravel:6 – 9
License:MIT
Last Updated:Jun 24, 2022
Links: GitHub  ·  Packagist
Maintainer: MilesChou

Slim Test

Latest Stable Version Build Status codecov License

A simple test helper for Slim Framework 3

The repository has some example in tests folder. app.php is a definition use simple Slim router, SlimCaseTest.php is testing for SlimCase class, and 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

$ composer require --dev mileschou/slim-test

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

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

It's easy to using Slim Test in Behat. 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

Execute all test suite use PHPUnit and Behat

$ 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

The Slim Test is licensed under the MIT license. See License File for more information.

Related Packages

league/factory-muffin

The goal of this package is to enable the rapid creation of objects for the purp...

16,327,163 529
laravel/browser-kit-testing

Provides backwards compatibility for BrowserKit testing in the latest Laravel re...

10,879,493 515
chekote/noun-store

Store and work with Nouns

98,113 8
itsgoingd/slim-facades

"Static" interface for various Slim features

57,670 74
itsgoingd/slim-services

Service manager for Slim compatible with Laravel packages

15,658 75

Version History

Version Released PHP Laravel License
v0.0.1 ^7.2 | ^8.0 ^6 | ^7 | ^8 | ^9 MIT