jeudi 19 octobre 2017

codeception api testing: How can I mock methods used during api call?

I use codeception to test my API. The internals of the endpoint make a request to an external server and I would like to mock/stub it. My test looks like this:

 public function it_provides_data_for_authenticated_request(ApiTester $I)
    {
        $I->amBearerAuthenticated('xxx');
        $I->haveHttpHeader('X-Requested-With', 'XMLHttpRequest');
        $I->sendPost('lookup', ['email' => 'test.user@example.com']);

        $I->seeResponseCodeIs(200);
        $I->seeResponseContainsJson([
            'info' => [ 'name' => 'Test User' ]
        ]);
    }

the lookup route itself calls a method that requests data from a 3rd pary server.

Aucun commentaire:

Enregistrer un commentaire