1 | <?php |
||
15 | class InclusionMatcher extends AbstractMatcher |
||
16 | { |
||
17 | /** |
||
18 | * Matches if an array or string contains the expected value. |
||
19 | * |
||
20 | * @param $actual |
||
21 | * @return mixed |
||
22 | * @throws InvalidArgumentException |
||
23 | */ |
||
24 | protected function doMatch($actual) |
||
25 | { |
||
26 | if ($actual instanceof Traversable) { |
||
27 | return $this->matchTraversable($actual); |
||
28 | } |
||
29 | |||
30 | if (is_array($actual)) { |
||
31 | return array_search($this->expected, $actual, true) !== false; |
||
32 | } |
||
33 | |||
34 | if (is_string($actual)) { |
||
35 | return strpos($actual, $this->expected) !== false; |
||
36 | } |
||
37 | |||
38 | throw new InvalidArgumentException('Inclusion matcher requires a string or array'); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | * |
||
44 | * @return TemplateInterface |
||
45 | */ |
||
46 | public function getDefaultTemplate() |
||
53 | |||
54 | private function matchTraversable(Traversable $actual) |
||
64 | } |
||
65 |