-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathQueryParamMatcher.php
More file actions
42 lines (31 loc) · 1.16 KB
/
QueryParamMatcher.php
File metadata and controls
42 lines (31 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
declare(strict_types=1);
namespace Brainbits\FunctionalTestHelpers\HttpClientMock\Matcher;
use Brainbits\FunctionalTestHelpers\HttpClientMock\RealRequest;
use function sprintf;
use function vsprintf;
final readonly class QueryParamMatcher implements Matcher
{
private string $value;
/** @param array<string> $placeholders */
public function __construct(private string $key, string $value, array $placeholders)
{
$this->value = vsprintf($value, $placeholders);
}
public function __invoke(RealRequest $realRequest): Hit|Mismatch|Missing
{
if (!$realRequest->hasQueryParam($this->key)) {
return Missing::missingQueryParam($this->key, $this->value);
}
$expectedValue = $this->value;
$realValue = $realRequest->getQueryParam($this->key);
if ($expectedValue !== $realValue) {
return Mismatch::mismatchingQueryParam($this->key, $expectedValue, $realValue);
}
return Hit::matchesQueryParam($this->key, $realValue);
}
public function __toString(): string
{
return sprintf('request.queryParams["%s"] === "%s"', $this->key, $this->value);
}
}