简体   繁体   中英

Codeception Functional API tests with Laravel5 authentication

I'm trying to test an API that requires users to be logged in via Laravel through the web. Javascript will be accessing a REST API with a CSRF token. When I try to test this using Codeception it seems like the authentication is not being recognized with the sendPOST call.

I'm using the following Modules in my Api Suite:

modules:
    enabled:
        - Laravel5
        - \Helper\Api
        - REST:
              depends: PhpBrowser
              url: http://app.dev/api/

Here is my test:

public function verifyFileIsRequired(ApiTester $I)
{
    $I->amLoggedAs($this->user);
    $I->sendPOST(self::URL_GOES_HERE);
    $I->seeResponseCodeIs(422);
}

I keep getting a 401 response code. I have a feeling that this is due to the sendPOST method not sending the Laravel session info. Is there a way to make this work?

Thanks!

Naktibalda pointed me in the right direction to get this solved. Posting answer incase someone else runs into this problem.

In my api.suite.yml I should have had REST module depend on Laravel5.

modules:
    enabled:
        - Laravel5
        - \Helper\Api
        - REST:
            depends: Laravel5    <-- this was the fix

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM