# Writing testable API apps in Slim framework

**URL:** <https://discourse.slimframework.com/t/writing-testable-api-apps-in-slim-framework/629>\
**Category:** Show and Tell\
**Created:** [August 17, 2016, 9:26pm UTC](https://discourse.slimframework.com/t/writing-testable-api-apps-in-slim-framework/629 "2016-08-17T21:26:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pyj\_jac](https://avatars.discourse-cdn.com/v4/letter/p/e36b37/32.png) [@pyj\_jac](https://discourse.slimframework.com/u/pyj_jac)\
**Post date:** [August 17, 2016, 9:26pm UTC](https://discourse.slimframework.com/t/writing-testable-api-apps-in-slim-framework/629/1 "2016-08-17T21:26:56Z")

</div>

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](https://medium.com/@Andela/writing-testable-api-apps-in-slim-framework-29905970941b#.hagke63so)

---

<div class="post-metadata">

**Author:** ![geggleto](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/geggleto/32/11_2.png) [@geggleto](https://discourse.slimframework.com/u/geggleto)\
**Post date:** [August 18, 2016, 12:45pm UTC](https://discourse.slimframework.com/t/writing-testable-api-apps-in-slim-framework/629/2 "2016-08-18T12:45:14Z")

</div>

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:

```php
class TodoGetAction {

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

```

Route

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

```

### Unit test

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

//Run assertions

```

`
