1: <?php
2:
3: /**
4: * This file is part of expect package.
5: *
6: * (c) Noritaka Horio <holy.shared.design@gmail.com>
7: *
8: * This source file is subject to the MIT license that is bundled
9: * with this source code in the file LICENSE.
10: */
11: namespace expect\matcher\strategy;
12:
13: final class StringInclusionStrategy implements InclusionStrategy
14: {
15: /**
16: * @var string
17: */
18: private $actualValue;
19:
20: /**
21: * @param string actualValues
22: */
23: public function __construct($actualValue)
24: {
25: $this->actualValue = $actualValue;
26: }
27:
28: /**
29: * <code>
30: * <?php
31: * $strategy = new StringInclusionStrategy('foo');
32: * $result = $strategy->match([ 'foo', 'bar' ]);.
33: *
34: * var_dump($result->isMatched()) // true
35: * var_dump($result->getMatchResults()); // ['foo']
36: * var_dump($result->getUnmatchResults()); // ['bar']
37: * ?>
38: * </code>
39: *
40: * @param array expectValues
41: */
42: public function match(array $expectValues)
43: {
44: $matchResults = [];
45: $unmatchResults = [];
46:
47: foreach ($expectValues as $expectValue) {
48: $position = strpos($this->actualValue, $expectValue);
49: if ($position !== false) {
50: $matchResults[] = $expectValue;
51: } else {
52: $unmatchResults[] = $expectValue;
53: }
54: }
55:
56: return new InclusionResult($expectValues, $matchResults, $unmatchResults);
57: }
58: }
59: