Codeception API测试响应以'N / A'形式返回

时间:2014-03-17 21:40:05

标签: api laravel response codeception

我正在使用Laravel和Codeception作为我的测试框架编写API。

我无法让Codeception返回我可以从Codeception获取的响应代码以及JSON响应。

我已经编写了一个简单的测试来从GET请求中获取用户列表。

测试如下:

$I = new ApiGuy($scenario);
$I->wantTo("access API methods if I'm authenticated as a User");

$I->sendGET('users');

$I->seeResponseIsJson();
$I->seeResponseCodeIs(200);

我可以看到结果虽然好,但似乎无法获得响应代码。

生成响应的路由如下:

Route::get('users', function() {

    $users = User::all();
    return Response::json($users->toArray(), 200);
});

Codeception的回应是:

Modules: PhpBrowser, REST, ApiHelper, Laravel4, Db, Filesystem
-----------------------------------------------------------------------------------------------
Trying to only access api methods if i'm authenticated as a user (UserAuthCept.php)       
Scenario:
* I send get "users"
  [Request] GET http://myapp-api.local/users
  [Response] [{"id":1,"firstname":"First","lastname":"User","email":"firstuser@test.com","phone":"","login":0,"status":0,"username":"firstuser","created_at":"2014-03-17 14:55:29","updated_at":"2014-03-17 14:55:29"},{"id":2,"firstname":"Second","lastname":"User","email":"seconduser@test.com","phone":"","login":0,"status":0,"username":"seconduser","created_at":"2014-03-17 14:55:30","updated_at":"2014-03-17 14:55:30"}]
  [Headers] {"date":["Mon, 17 Mar 2014 17:50:22 GMT"],"server":["Apache"],"x-powered-by":["PHP\/5.4.26-1~dotdeb.0"],"cache-control":["no-cache"],"x-frame-options":["SAMEORIGIN"],"set-cookie":["laravel_session=eyJpdiI6Im9PZ09qYzdZSWI2bnRsTXFxOUJBelFRVUpEVXFKZVp3VFlMU1h1c3lkRG89IiwidmFsdWUiOiJwSDdCVzlMSjU5SERwWmNENzBsOUFaRExXbit3SUcxSG9vRmpRcGN2cXNrK2kzVU1NT0FaTGdsNGZObG1NT01nN01QdlZXU2FCdGpPcjMzY0dJak1hdz09IiwibWFjIjoiOWRmZDEwNGVhNWQ5MWQyMmRiMTBiOWVjNGNkYjA4ZmFlYzg4NjBmYjhjM2Q2ZmRlNWQ3NzlkY2I0NDhlOTVkYiJ9; expires=Mon, 17-Mar-2014 19:50:22 GMT; path=\/; httponly"],"vary":["Accept-Encoding"],"transfer-encoding":["chunked"],"content-type":["application\/json"]}
  [Status] 200
* I see response is json 
* I see response code is 200
 FAIL 

-----------------------------------------------------------------------------------------------


Time: 1.05 seconds, Memory: 9.50Mb

There was 1 failure:

---------
1) Failed to only access api methods if i'm authenticated as a user in UserAuthCept.php
Sorry, I couldn't see response code is 200:
Failed asserting that 'N/A' matches expected 200.

Scenario Steps:
3. I see response code is 200
2. I see response is json 
1. I send get "users"


FAILURES!
Tests: 1, Assertions: 2, Failures: 1.

1 个答案:

答案 0 :(得分:1)

在关注代码并查看seeResponseCodeIs的所有实例后,意识到它正在执行' Framework'版。拿出Laravel4模块,它现在可以工作了!