Skip to content

Instantly share code, notes, and snippets.

@ambengers
Last active March 26, 2019 08:41
Show Gist options
  • Select an option

  • Save ambengers/dfe77d77c6290b35e1e8d5a68d4375d2 to your computer and use it in GitHub Desktop.

Select an option

Save ambengers/dfe77d77c6290b35e1e8d5a68d4375d2 to your computer and use it in GitHub Desktop.
Trait for testing laravel-query-filter package
<?php
namespace Tests\Feature\Concerns;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Foundation\Testing\TestResponse;
trait InteractsWithQueryFilters
{
/**
* Set the filters of the request
*
* @param string $model
* @param string $filter
* @param array $parameters
*/
public function setRequestFilters($modelClass, $filterClass, array $parameters)
{
return $modelClass::filter(
new $filterClass(
app(Request::class)->merge($parameters)
)
);
}
/**
* Set the data to the response object as content
*
* @param mixed $data
*/
public function setResponseContent($data)
{
return TestResponse::fromBaseResponse(
app(Response::class)->setContent($data)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment