Writing testable API apps in Slim framework

Hi Guys,

I’ve just written an article regarding writing testable slim App…
Check it out and share your thoughts.
Writing testable API apps in Slim framework

2 Likes

Note to users looking for advise on testing…

There is a much easier way.
If you refactor your route action functions into an Object it is much easier to unit test your routes.

Example:

class TodoGetAction {

    public function __invoke($request, $response, $args) {
        //stuff here
    }
}

Route

$app->get('/todo/{id}', 'TodoGetAction');

Unit test

$action = new TodoGetAction();
//Mock Request, Response
$response = $action->__invoke($request, $response);

//Run assertions

`