1: <?php
2:
3: namespace Peridot\Leo\Matcher;
4:
5: use ArrayAccess;
6: use InvalidArgumentException;
7: use Peridot\Leo\Matcher\Template\ArrayTemplate;
8: use Peridot\Leo\Matcher\Template\TemplateInterface;
9:
10: 11: 12: 13: 14:
15: class InclusionMatcher extends AbstractMatcher
16: {
17: 18: 19: 20: 21: 22: 23:
24: protected function doMatch($actual)
25: {
26:
27: if (is_array($actual) or $actual instanceof ArrayAccess) {
28: return array_search($this->expected, $actual, true) !== false;
29: }
30:
31: if (is_string($actual)) {
32: return strpos($actual, $this->expected) !== false;
33: }
34:
35: throw new InvalidArgumentException("Inclusion matcher requires a string or array");
36: }
37:
38: 39: 40: 41: 42:
43: public function getDefaultTemplate()
44: {
45: return new ArrayTemplate([
46: 'default' => 'Expected {{actual}} to include {{expected}}',
47: 'negated' => 'Expected {{actual}} to not include {{expected}}'
48: ]);
49: }
50: }
51: