1 | <?php |
||
37 | abstract class ListMatcher extends BaseMatcher |
||
38 | { |
||
39 | /** |
||
40 | * @var array |
||
41 | */ |
||
42 | private $failedMatchers = array(); |
||
43 | |||
44 | /** |
||
45 | * @var array |
||
46 | */ |
||
47 | private $matchers = array(); |
||
48 | |||
49 | /** |
||
50 | * Creates an abstract matcher to match a number of Matchers against Events contained inside a Collection. |
||
51 | * |
||
52 | * @param Matcher[] $matchers The matchers to match the individual Events in the Collection |
||
53 | */ |
||
54 | 28 | protected function __construct(array $matchers) |
|
58 | |||
59 | /** |
||
60 | * @param mixed $item |
||
61 | * @return bool |
||
62 | */ |
||
63 | 28 | public function matches($item) |
|
67 | |||
68 | /** |
||
69 | * Evaluates the matcher for argument <code>item</code>. The item has been verified to be a list, but the exact |
||
70 | * type of contents of a list cannot be verified, due to Erasure of Generic Types. |
||
71 | * |
||
72 | * @param array $item the object against which the matcher is evaluated. |
||
73 | * @return boolean <code>true</code> if <code>item</code> matches, otherwise <code>false</code>. |
||
74 | * |
||
75 | * @see BaseMatcher |
||
76 | */ |
||
77 | abstract protected function matchesList(array $item); |
||
78 | |||
79 | /** |
||
80 | * Matches all the remaining Matchers in the given <code>matcherIterator</code> against <code>null</code>. |
||
81 | * |
||
82 | * @param \Iterator $matcherIterator The iterator potentially containing more matchers |
||
83 | * @return boolean true if no matchers remain or all matchers succeeded |
||
84 | */ |
||
85 | 11 | protected function matchRemainder(\Iterator $matcherIterator) |
|
100 | |||
101 | /** |
||
102 | * Report the given <code>matcher</code> as a failing matcher. This will be used in the error reporting. |
||
103 | * |
||
104 | * @param Matcher $matcher The failing matcher. |
||
105 | */ |
||
106 | 10 | protected function reportFailed(Matcher $matcher) |
|
110 | |||
111 | /** |
||
112 | * Returns a read-only list of Matchers, in the order they were provided in the constructor. |
||
113 | * |
||
114 | * @return Matcher[] a read-only list of Matchers, in the order they were provided in the constructor |
||
115 | */ |
||
116 | 28 | protected function getMatchers() |
|
120 | |||
121 | /** |
||
122 | * Describes the type of collection expected. To be used in the sentence: "list with ... of: <description of |
||
123 | * matchers>". E.g. "all" or "sequence". |
||
124 | * |
||
125 | * @param Description $description the description to append the collection type to |
||
126 | */ |
||
127 | protected abstract function describeCollectionType(Description $description); |
||
128 | |||
129 | 8 | public function describeTo(Description $description) |
|
155 | |||
156 | /** |
||
157 | * The message to append behind a failing matcher. Defaults to FAILED!. |
||
158 | * |
||
159 | * @return string The message to append behind a failing matcher |
||
160 | */ |
||
161 | 3 | protected function failedMatcherMessage() |
|
165 | |||
166 | /** |
||
167 | * The separator to use between the two last events. Defaults to "and". |
||
168 | * |
||
169 | * @return string The separator to use between the two last events. Defaults to "and". |
||
170 | */ |
||
171 | 6 | protected function getLastSeparator() |
|
175 | |||
176 | } |
||
177 |