Can Aspecktmock used in Codeception API testing?

47 views Asked by At

We use Codeception with Phalcon.

We are trying to add testing around an API. This API has DB saves and other application logic. Assume our requirement is to receive 403 HTTP status If the DB save has failed (part of an error handling we do).

Now we want to mock that DB save (which is in our application) so that we can verify that our endpoint returns the correct HTTP status code, in case an application function has failed.

Our API endpoint’s code looks something like

if(!Model::dbSave()){
    return 403;
}
return 200;

Our testcase: When the DB Save failed I would see a 403.

test::double({Model name in the Application}, ['dbSave' => false ]);
$I->sendGet("uri");
$I->seeResponseCodeIs(403);

We are having trouble mocking the application function this way. How could we mock application functions via API tests?

0

There are 0 answers