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 ArrayInclusionStrategy implements InclusionStrategy
14: {
15: /**
16: * @var array
17: */
18: private $actualValues;
19:
20: /**
21: * @param array actualValues
22: */
23: public function __construct(array $actualValues)
24: {
25: $this->actualValues = $actualValues;
26: }
27:
28: /**
29: * <code>
30: * <?php
31: * $strategy = new ArrayInclusionStrategy([ 1, 2 ]);
32: * $result = $strategy->match([ 1, 2, 3 ]);.
33: *
34: * var_dump($result->isMatched()) // true
35: * var_dump($result->getMatchResults()); // [ 1, 2 ]
36: * var_dump($result->getUnmatchResults()); // [ 3 ]
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: if (in_array($expectValue, $this->actualValues)) {
49: $matchResults[] = $expectValue;
50: } else {
51: $unmatchResults[] = $expectValue;
52: }
53: }
54:
55: return new InclusionResult($expectValues, $matchResults, $unmatchResults);
56: }
57: }
58: