Skip to content

Commit

Permalink
Assertion to validate page/limit in GetEvents + added params in GET m…
Browse files Browse the repository at this point in the history
…ethod support
  • Loading branch information
patrykwozinski authored and jorge07 committed Jul 25, 2018
1 parent 20b4d69 commit ff0c1c9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/UI/Http/Rest/Controller/Event/GetEventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Application\Query\Collection;
use App\Application\Query\Event\GetEvents\GetEventsQuery;
use App\UI\Http\Rest\Controller\QueryController;
use Assert\Assertion;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -26,8 +27,11 @@ class GetEventsController extends QueryController
*/
public function __invoke(Request $request): JsonResponse
{
$page = (int) $request->get('page', 1);
$limit = (int) $request->get('limit', 50);
$page = $request->get('page', 1);
$limit = $request->get('limit', 50);

Assertion::integer($page, 'Page number must be an integer');
Assertion::integer($limit, 'Limit results must be an integer');

$query = new GetEventsQuery((int) $page, (int) $limit);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function events_should_be_present_in_elastic_search()

$this->refreshIndex();

$this->get('/api/events?limit=1');
$this->get('/api/events', ['limit' => 1]);

self::assertEquals(200, $this->client->getResponse()->getStatusCode());

Expand Down Expand Up @@ -77,7 +77,7 @@ public function events_not_present_in_elastic_search_in_other_page()

$this->refreshIndex();

$this->get('/api/events?page=2');
$this->get('/api/events', ['page' => 2]);

self::assertEquals(200, $this->client->getResponse()->getStatusCode());

Expand Down
4 changes: 2 additions & 2 deletions tests/UI/Http/Rest/Controller/JsonApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ protected function post(string $uri, array $params)
);
}

protected function get(string $uri)
protected function get(string $uri, array $parameters = [])
{
$this->client->request(
'GET',
$uri,
[],
$parameters,
[],
[
'CONTENT_TYPE' => 'application/json',
Expand Down

0 comments on commit ff0c1c9

Please sign in to comment.