doudui1850 2017-01-17 23:29
浏览 276

Codeception Lumen API - '未定义'Auth guard driver [api]'在单个测试中发出多个请求时

I have an API I'm building with Lumen 5.3. For Authentication I'm using Laravel Passport (ported to Lumen via the dusterio/lumen-passport package).

All works well in Postman, and all tests pass fine with a single request. However once I make a test that has multiple requests I get the error: 'Auth guard driver [api] is not defined'. The guard is defined in my auth config, and as I said works perfect outside of this test case.

Example test:

    public function it_requires_users_password_when_updating_email(ApiTester $I)
    {
        $I->wantTo('Require password when updating email');
        $user = factory(\App\User::class)->create();
        $I->sendPOST('oauth/token', [
            'grant_type' => 'password',
            'client_id' => 1,
            'client_secret' => env('OAUTH_SECRET'),
            'username' => $user->email,
            'password' => 'password',
            'scope' => ''
        ]);
        $token = $I->grabDataFromResponseByJsonPath('$.access_token')[0];
        $I->amBearerAuthenticated($token);
        $I->sendPUT('users/' . $user->id, ['email' => 'bender.rodriguez@planetexpress.com']);
        $I->seeResponseCodeIs(422);
        $I->seeRecord('users', array_only($user->toArray(), ['id', 'email']));
        $I->dontSeeRecord('users', ['id' => $user->id, 'email' => 'bender.rodriguez@planetexpress.com']);
        $I->sendPUT('users/' . $user->id, ['email' => 'bender.rodriguez@planetexpress.com', 'password' => 'password']);
        $I->seeResponseCodeIs(200);
        $I->seeRecord('users', ['id' => $user->id, 'email' => 'bender.rodriguez@planetexpress.com']);
    }

The test passes fine if I remove the last 3 lines (everything from the 2nd sendPUT request), but once I include that, I get the error.

Any ideas?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法