Writing testable API apps in Slim framework


#1

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

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

`