1

I want to test all my API endpoints with codeception.

I started off with a more model-based approach:

class UserCest
{
    public function it_can_request_its_own_status (ApiTester $I) {
        $user = $I->amLoggedIn();
        $I->sendGET('/users/'.$user->id.'/status');
        $I->seeResponseCodeIs(200);
        $I->seeResponseContainsJson(['status' => 'active']);
    }
}

Now I realized that I might want to map the test directly to the routes to make it more obvious what route is tested. I thought that this would therefore rather refer to the controller that is used by the routes rather than models:

class UserControllerCest
{
    public users__user__status (ApiTester $I) {
        $route = __FUNCTION__;
        $user = $I->amLoggedIn();
        $url = $this->fillRouteWithUserId($route, $user);
        $I->sendGET($url);
        $I->seeResponseCodeIs(200);
        $I->seeResponseContainsJson(['status' => 'active']);
    }
}

What (other) approach is suitable for testing my API? Maybe to create a separate Cest for every route?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.