forked from brainbits/functional-test-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHit.php
More file actions
76 lines (61 loc) · 1.97 KB
/
Hit.php
File metadata and controls
76 lines (61 loc) · 1.97 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
declare(strict_types=1);
namespace Brainbits\FunctionalTestHelpers\HttpClientMock\Matcher;
use function is_array;
use function Safe\json_encode;
final readonly class Hit
{
private function __construct(
public string $matcher,
public string|null $key,
public int $score,
public string $actual,
) {
}
public static function catchAll(): self
{
return new self('catchAll', null, 1, 'Match everything');
}
public static function matchesMethod(string $method): self
{
return new self('method', null, 10, $method);
}
public static function matchesUri(string $uri): self
{
return new self('uri', null, 20, $uri);
}
public static function matchesHeader(string $key, string $value): self
{
return new self('header', $key, 5, $value);
}
/** @param string|mixed[] $value */
public static function matchesQueryParam(string $key, string|array $value): self
{
return new self('queryParam', $key, 5, is_array($value) ? json_encode($value) : $value);
}
public static function matchesRequestParam(string $key, string $value): self
{
return new self('requestParam', $key, 5, $value);
}
public static function matchesContent(string $content): self
{
return new self('content', null, 5, $content);
}
public static function matchesJson(string $json): self
{
return new self('json', null, 5, $json);
}
public static function matchesXml(string $xml): self
{
return new self('xml', null, 5, $xml);
}
/** @param array{name: string, filename?: string, mimetype?: string, content?: string} $multipart */
public static function matchesMultipart(array $multipart): self
{
return new self('multipart', $multipart['name'], 5, $multipart['name']);
}
public static function matchesThat(): self
{
return new self('that', null, 5, 'Match that-callback');
}
}