When testing an API Endpoint with:
$this->call(
'GET',
'api/v3/user?page[size]=20',
[ 'page' => [ 'size' => 20 ] ]
);
With a route:
$app->group(['prefix'=>'api/v3','namespace'=>'MyAPI\V3core\Http\Controllers'], function ($app) {
/* User */
$app->get('user', ['as' => 'user.read', 'uses' => 'UserController@read');
});
With a controller:
public function read(Request $request, $id = false)
{
dd($request);
}
dd($request); outputs a \Symfony\Component\HttpFoundation\Response with the request attributes empty:
+request: Symfony\Component\HttpFoundation\ParameterBag {
#parameters: []
}
Whereas when I request the same API endpoint via Postman, the request Object is returned like:
+request: ParameterBag {#151
#parameters: array:1 [
"page" => array:1 [
"size" => "20"
]
]
}
This causes pagination or any query driven function to be untestable.
It's worth mentioning that the returned Response from PHPUnit has
+query: Symfony\Component\HttpFoundation\ParameterBag {#277
#parameters: array:1 [
"page" => array:1 [
"size" => 20
]
]
}
And that Pagination is handled via http://ift.tt/1UUPWmu
Aucun commentaire:
Enregistrer un commentaire