|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace spec\PHPSpec; |
|
6
|
|
|
|
|
7
|
|
|
use PhpSpec\Exception\Example\FailureException; |
|
8
|
|
|
use PhpSpec\Matcher\BasicMatcher; |
|
9
|
|
|
|
|
10
|
|
|
final class OneOfMatcher extends BasicMatcher |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @param mixed $subject |
|
14
|
|
|
* @param mixed[] $arguments |
|
15
|
|
|
*/ |
|
16
|
|
|
public function supports(string $name, $subject, array $arguments): bool |
|
17
|
|
|
{ |
|
18
|
|
|
return 'beOneOf' === $name; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param mixed $subject |
|
23
|
|
|
* @param mixed[] $arguments |
|
24
|
|
|
*/ |
|
25
|
|
|
protected function matches($subject, array $arguments): bool |
|
26
|
|
|
{ |
|
27
|
|
|
if (1 === \count($arguments) && \is_array(current($arguments))) { |
|
28
|
|
|
$arguments = current($arguments); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
return \in_array($subject, $arguments, true); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param mixed $subject |
|
36
|
|
|
* @param mixed[] $arguments |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function getFailureException(string $name, $subject, array $arguments): FailureException |
|
39
|
|
|
{ |
|
40
|
|
|
if (1 === \count($arguments) && \is_array(current($arguments))) { |
|
41
|
|
|
$arguments = current($arguments); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return new FailureException( |
|
45
|
|
|
\sprintf( |
|
46
|
|
|
'"%s" is not one of ["%s"]', |
|
47
|
|
|
$subject, |
|
48
|
|
|
implode('", "', $arguments) |
|
49
|
|
|
) |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param mixed $subject |
|
55
|
|
|
* @param mixed[] $arguments |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function getNegativeFailureException(string $name, $subject, array $arguments): FailureException |
|
58
|
|
|
{ |
|
59
|
|
|
if (1 === \count($arguments) && \is_array(current($arguments))) { |
|
60
|
|
|
$arguments = current($arguments); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return new FailureException( |
|
64
|
|
|
\sprintf( |
|
65
|
|
|
'"%s" is one of ["%s"]', |
|
66
|
|
|
$subject, |
|
67
|
|
|
implode('", "', $arguments) |
|
68
|
|
|
) |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|