Codeception API测试响应返回为';不适用';

Codeception API测试响应返回为';不适用';,api,laravel,response,codeception,Api,Laravel,Response,Codeception,我正在编写一个API,使用Laravel和Codeception作为我的测试框架 我很难让Codeception返回一个响应代码,我可以从Codeception以及JSON响应中获取该代码 我编写了一个简单的测试,从get请求中获取用户列表 测试如下: $I = new ApiGuy($scenario); $I->wantTo("access API methods if I'm authenticated as a User"); $I->sendGET('users');

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

我很难让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.

在遵循代码并查看seeResponseCodeIs的所有实例后,意识到它正在执行“框架”版本。取出了Laravel4模块,现在可以工作了

我可以看到“N/A”的来源:
受保护的函数getResponseStatusCode(){//取决于Symfony版本$response=$this->client->getInternalResponse();if(方法_存在($response,'getStatus'))返回$response->getStatus();if(方法_存在($response,'getStatusCode'))return$response->getStatusCode();return“N/A”}
因此我尝试添加Symfony2模块,但现在说模块要求未得到满足。我希望有一个解决方案,它不涉及删除Laravel4模块-我使用它来设置环境、过滤器、,在对我的API运行测试之前,请等。如果其他人有此问题,我通过将套件配置中的Laravel4模块移动到阵列的开头来解决此问题-看起来需要在REST模块之前加载它。