Search code examples
phplaravelphpunitlaravel-5.4dingo-api

Laravel 5.4 upgrade broke API Dingo tests


I use Laravel 5.3 with Dingo to manage the API requests. I am trying to upgrade to Laravel 5.4 but my tests are failing.

Here is a case:

$request = $this->get('/api/authenticated-user', $this->headers());
$limit = $request->response->headers->get("X-RateLimit-Limit");
$times = $request->response->headers->get("X-RateLimit-Remaining") - 1;
do {
    $request = $this->get('/api/authenticated-user', $this->headers());
    $request->seeHeader("X-RateLimit-Limit", $limit);
    $request->seeHeader("X-RateLimit-Remaining", $times);
    $request->seeStatusCode(($times == 0 ? 429 : 200));
    $times--;
} while ($times > 0);

Before upgrade it worked like a charm, but now it is returning:

Undefined property: Dingo\Api\Http\Response::$response

This error happens in the second line. If I remove response it works:

$limit = $request->headers->get("X-RateLimit-Limit");

However the following line fails:

$request->seeHeader("X-RateLimit-Limit", $limit);

In this case seeHeaderis not defined.

I changed composer from "dingo/api": "1.0.*@dev" to "dingo/api": "v1.0.0-beta8".


Solution

  • Just realise the "problem" is in Laravel not in Dingo. The error message misguided me.

    Laravel 5.4 has a new testing layer, in order to provide compatibility there is a package. Laravel upgrade guide has all the information: https://laravel.com/docs/5.4/upgrade in Testing section.