【发布时间】:2015-11-02 10:11:07
【问题描述】:
我是 Codeception 的新手,我正在尝试测试我使用 Laravel 5 构建的 Web 服务。我正在遵循指南 here。
所以我先创建了一个叫 api 的套件:
codecept generate:suite api
api.suite.yml
class_name: ApiTester
modules:
enabled:
- REST:
url: http://localhost:8000/api/
depends: Laravel5
AuthenticateUserCept.php
<?php
$I = new ApiTester($scenario);
$I->wantTo('authenticate a user');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
$I->sendPOST('/authenticate', [
'username' => 'archive',
'email' => 'admin@admin.com',
'password' => 'password'
]);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
我已经使用 Postman 尝试过,它运行良好。 /authenticate 路由采用 3 个参数并愉快地吐出 JWT 令牌,但我无法使其与 Codeception 一起使用。
1) Failed to authenticate a user in AuthenticateUserCept (tests/api//AuthenticateUserCept.php)
Step I see response code is 200
Fail Failed asserting that 500 matches expected 200.
Scenario Steps:
3. $I->seeResponseCodeIs(200)
2. $I->sendPOST("/authenticate",{"username":"archive","email":"admin@admin.com","password":"password"})
1. $I->haveHttpHeader("Content-Type","application/x-www-form-urlencoded")
我哪里错了?此外,我仍然不清楚如何重构这个特定的测试,以便为我提出的其他请求提供 JWT。任何帮助表示赞赏。
编辑 api.suite.yml 中的更改
class_name: ApiTester
modules:
enabled:
- REST:
url: http://localhost:8000/api/
depends: Laravel5
config:
Laravel5:
environment_file: .env.testing
【问题讨论】:
标签: php laravel laravel-5 codeception