1: <?php
2: namespace Peridot\Leo\Matcher;
3:
4: use Peridot\Leo\Matcher\Template\ArrayTemplate;
5: use Peridot\Leo\Matcher\Template\TemplateInterface;
6:
7: /**
8: * SubStringMatcher determines if an actual string contains the expected sub string.
9: *
10: * @package Peridot\Leo\Matcher
11: */
12: class SubStringMatcher extends AbstractMatcher
13: {
14: /**
15: * Match that actual value has the expected sub string.
16: *
17: * @param string $actual
18: * @return mixed
19: */
20: protected function doMatch($actual)
21: {
22: if (! is_string($actual)) {
23: throw new \InvalidArgumentException("SubStringMatcher requires string value");
24: }
25:
26: return strpos($actual, $this->expected) !== false;
27: }
28:
29: /**
30: * {@inheritdoc}
31: *
32: * @return TemplateInterface
33: */
34: public function getDefaultTemplate()
35: {
36: return new ArrayTemplate([
37: 'default' => 'Expected {{actual}} to contain {{expected}}',
38: 'negated' => 'Expected {{actual}} to not contain {{expected}}'
39: ]);
40: }
41: }
42: