Giter Club home page Giter Club logo

codeception-slim-module's Introduction

Codeception Slim Module

Master Build Status Packagist Stable Version Packagist License Libraries.io for GitHub

This module allows you to run tests inside Slim 3 Microframework.
Based on ZendExpressive Module.

Install

Via commandline:

composer require --dev herloct/codeception-slim-module

Via composer.json:

{
  "require-dev": {
    "herloct/codeception-slim-module": "^1.1"
  }
}

Config

Put this on your codeception.yml

modules:
  config:
    \Herloct\Codeception\Module\Slim:
      container: path/to/container.php
    REST:
      depends: \Herloct\Codeception\Module\Slim

Or on your tests/functional.suite.yml

modules:
  enabled:
    - \Helper\Functional
    - \Herloct\Codeception\Module\Slim:
        container: path/to/container.php
    - REST:
        depends: \Herloct\Codeception\Module\Slim

The container properties is a relative path to file which returns your App's Container.
Here is the minimum container.php contents.

require __DIR__.'/vendor/autoload.php';

use Psr\Container\ContainerInterface;
use Slim\App;
use Slim\Container;

$container = new Container([
    App::class => function (ContainerInterface $c) {
        $app = new App($c);

        // routes and middlewares here

        return $app;
    }
]);

return $container;

You could use this Sample Project as a reference.

API

  • app - instance of \Slim\App
  • container - instance of \Psr\Container\ContainerInterface
  • client - BrowserKit client

Todos

  • Add more acceptance/functional tests other than REST.

codeception-slim-module's People

Contributors

abrownpltw avatar herloct avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

codeception-slim-module's Issues

request->getParsedBody() returns null

Hello,

Thank you for writing this library to integrate slim PHP with codeception. I've found it very handy so far. That being said, I believe I have found a bug. When using the codeception-slim-module, the request->getParsedBody() method always returns null. I believe this is due to the following code in Lib\Connector\Slim.php lines 56-61:

$parsed = [];
if ($request->getMethod() !== 'GET') {
    $parsed = $request->getParameters();
}
$slimRequest = $slimRequest
  ->withParsedBody($parsed);

My 'fix' for the bug was to remove those lines :) but I'm not sure if I'm breaking some other functionality in doing so. I'm not sure what the original intention for that code was and I am hoping you can help guide me to a solution for the issue. I'm working on a test that will illustrate the bug and will submit a pull request referencing this issue.

Module \Herloct\Codeception\Module\Slim could not be found and loaded

I have not been able to enabled this module to work with my Slim REST API. I have followed the README.md but it is not very clear and should be expanded.

[Codeception\Exception\ConfigurationException]
Module \Herloct\Codeception\Module\Slim could not be found and loaded

Is there any chance you could expand the documentation a bit further as there is no other information online.

Thanks.

use app container to get request, response, etc...

Hello,

I ran into an issue where I was extending the slim response in the container for my app and the test was failing because we are creating new Slim\Http\Response's instead of getting them from the app's container in this module.

I only have a need right now to retrieve the response from the container. However, I could imagine that anything that's in the container is fair game for extension. With that in mind, I looked at retrieving the request object from the container but that one seems to be more difficult since we have to inject a mock environment into Slim. Which brings me to why I'm opening this issue.

Currently, this module expects the user to fully instantiate a Slim app inside a DI container. This makes it difficult (perhaps impossible) for the module to inject the mock environment into Slim later down the road which, in turn, makes it difficult for us to use the request in the app's container.

Personally, I think the way the container is structured would have to be changed. Maybe we could require 'middleware' and 'routes' services in the container instead of App::class. Then we could instantiate the slim app with our mock environment and add the middleware and routes from the container to our app.

Of course, if there's a way to just Slim to parse the mock environment after it's instantiated, that would work too.

I'd like to get your thoughts on how we might be able to get around this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.