Skip to content

Codeception module to write functional tests with Slim framework integration.

License

Notifications You must be signed in to change notification settings

iliayatsenko/codeception-slim-module

This branch is 2 commits ahead of, 8 commits behind DoclerLabs/codeception-slim-module:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
Ilia Yatsenko
Oct 18, 2022
a65af92 · Oct 18, 2022

History

14 Commits
Mar 8, 2022
Oct 14, 2022
Nov 5, 2020
Oct 13, 2020
Oct 13, 2020
Mar 8, 2022
May 7, 2021
Nov 5, 2020
Mar 8, 2022
Oct 18, 2022
Oct 5, 2020
May 7, 2021
Oct 18, 2022
Oct 13, 2020
Oct 14, 2022
Oct 13, 2020

Repository files navigation

DoclerLabs - Codeception Slim Module

Build Status PHPStan Level

This module allows you to run functional tests inside Slim 4 Microframework without HTTP calls, so tests will be much faster and debug could be easier.

Inspiration comes from herloct/codeception-slim-module library.

Install

Minimal requirements

  • php: ^8.0
  • slim/slim: ^4.7
  • codeception/codeception: ^5.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

For PHP 7 support, please use docler-labs/codeception-slim-module:^2.0 version

composer require --dev docler-labs/codeception-slim-module "^2.0"

If you use Slim v3, please use the previous version from library:

composer require --dev docler-labs/codeception-slim-module "^1.0"

Configuration

Example (test/suite/functional.suite.yml)

modules:
  enabled:
    - REST:
        depends: DoclerLabs\CodeceptionSlimModule\Module\Slim

  config:
    DoclerLabs\CodeceptionSlimModule\Module\Slim:
      application: path/to/application.php

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\Factory\AppFactory;

$app = AppFactory::create();

// Add routes and middlewares here.

return $app;

Testing your API endpoints

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',
            ]
        );
    }
}

About

Codeception module to write functional tests with Slim framework integration.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 95.2%
  • Makefile 4.8%