87779

Codeception API testing response comes back as 'N/A'

I am writing an API using Laravel and Codeception as my testing framework.

I am having trouble getting Codeception to come back with a response code that I can pick up from Codeception as well as a JSON response.

I've written a simple test to get a list of users from a GET request.

The test is as follows:

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

I can see the results coming though ok, just cant seem to get the response code.

The route that generates the response is as follows:

Route::get('users', function() { $users = User::all(); return Response::json($users->toArray(), 200); });

The response from Codeception is:

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.

Answer1:

After following the code and looking at all instances of seeResponseCodeIs, realised it was executing the 'Framework' version. Took out the Laravel4 module and it now works!

Recommend

  • Get the value of variable and assign as attribute in C#
  • How to protect the mp3 file from read or copy on Android?
  • Mapping two workspace folders to the same working directory
  • call a java program from a webapp in tomcat server - the java program is out side of tomcat server
  • PWA with multiple pages
  • Should I be afraid to use UDP to make a client/server broadcast talk?
  • Ionic storage “get” returns null only on the second call within method
  • Google OAuth: can't get refresh token with authorization code
  • What command do i need to pass in SabreCommandLLSRQ to get current price of PNR?
  • Is there a way to dynamically embed PDF Files in a JSP pulled from the file system?
  • Can't delete or rename original file after resizing
  • Execute scripts AJAX returns
  • Authentication in Play! and RestEasy
  • How can I extract results of aggregate queries in slick?
  • jQuery ready not fired after rails link_to is clicked
  • Needing to do .toArray() to get output of mongodb .find() on key name not value
  • Bad request using file_get_contents for PUT request in PHP
  • Seeking advice on Jetty HttpClient Hang
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Using variable in a value field in jMeter
  • Why is an OPTIONS request sent to the server?
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • DotNetZip - Calculate final zip size before calling Save(stream)
  • How to add date and time under each post in guestbook in google app engine
  • Hazelcast - OperationTimeoutException
  • RestKit - RKRequestDelegate does not exist
  • Is there a mandatory requirement to switch app.yaml?
  • Matrix multiplication with MKL
  • File upload with ng-file-upload throwing error
  • ExecuteAsync RestSharp to allow backgroundWorker CancellationPending c#
  • Revoking OAuth Access Token Results in 404 Not Found
  • AngularJs get employee from factory
  • Turn off referential integrity in Derby? is it possible?
  • Authorize attributes not working in MVC 4
  • Busy indicator not showing up in wpf window [duplicate]
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF
  • How to push additional view controllers onto NavigationController but keep the TabBar?