Last active
March 26, 2019 08:41
-
-
Save ambengers/dfe77d77c6290b35e1e8d5a68d4375d2 to your computer and use it in GitHub Desktop.
Trait for testing laravel-query-filter package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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