This module allows you to run functional tests inside Slim 3 Microframework without HTTP calls, so tests will be much faster and debug could be easier.
Inspiration comes from herloct/codeception-slim-module library.
- php:
^7.2 || ^8.0
- slim/slim:
^3.1
- codeception/codeception:
^4.0
If you don't know Codeception, please check Quickstart Guide first.
If you already have Codeception installed in your Slim application, you can add codeception-slim-module with a single composer command.
composer require --dev docler-labs/codeception-slim-module
Example (test/suite/functional.suite.yml
)
modules:
enabled:
- DoclerLabs\CodeceptionSlimModule\Module\Slim:
application: path/to/application.php
- REST:
depends: DoclerLabs\CodeceptionSlimModule\Module\Slim
The application
property is a relative path to file which returns your Slim\App
instance.
Here is the minimum application.php
content:
require __DIR__ . '/vendor/autoload.php';
use Slim\App;
$app = new App();
// Add routes and middlewares here.
return $app;
class UserCest
{
public function getUserReturnsWithEmail(FunctionalTester $I): void
{
$I->haveHttpHeader('Content-Type', 'application/json');
$I->sendGET('/users/John');
$I->seeResponseCodeIs(200);
$I->seeResponseContainsJson(
[
'email' => 'john.doe@example.com',
]
);
}
}