adrema/tests/Lib/MakesHttpCalls.php

40 lines
971 B
PHP
Raw Normal View History

2023-02-23 22:43:13 +01:00
<?php
namespace Tests\Lib;
use Illuminate\Testing\TestResponse;
trait MakesHttpCalls
{
/**
* @param array<string, mixed> $filter
2024-02-08 21:04:00 +01:00
* @param array<string, mixed> $routeParams
2023-02-23 22:43:13 +01:00
*/
2024-02-08 21:04:00 +01:00
public function callFilter(string $routeName, array $filter, array $routeParams = []): TestResponse
2023-02-23 22:43:13 +01:00
{
2024-02-08 21:04:00 +01:00
return $this->call('GET', $this->filterUrl($routeName, $filter, $routeParams));
2023-02-23 22:43:13 +01:00
}
/**
* @param array<string, mixed> $filter
2024-02-08 21:04:00 +01:00
* @param array<string, mixed> $routeParams
2023-02-23 22:43:13 +01:00
*/
2024-02-08 21:04:00 +01:00
public function filterUrl(string $routeName, array $filter, array $routeParams = []): string
2023-02-23 22:43:13 +01:00
{
$params = [
2024-01-30 00:49:22 +01:00
'filter' => $this->filterString($filter),
2024-02-08 21:04:00 +01:00
...$routeParams
2023-02-23 22:43:13 +01:00
];
return route($routeName, $params);
}
2024-01-30 00:49:22 +01:00
/**
* @param array<string, mixed> $filter
*/
public function filterString(array $filter): string
{
return base64_encode(rawurlencode(json_encode($filter)));
}
2023-02-23 22:43:13 +01:00
}