Matchers::listWithAllOf()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * The software is based on the Axon Framework project which is
17
 * licensed under the Apache 2.0 license. For more information on the Axon Framework
18
 * see <http://www.axonframework.org/>.
19
 * 
20
 * This software consists of voluntary contributions made by many individuals
21
 * and is licensed under the MIT license. For more information, see
22
 * <http://www.governor-framework.org/>.
23
 */
24
25
namespace Governor\Framework\Test\Matchers;
26
27
use Hamcrest\Matcher;
28
29
/**
30
 * Utility class containing static methods to obtain instances of (List) Matchers.
31
 * 
32
 * @author    "David Kalosi" <[email protected]>  
33
 * @license   <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> 
34
 */
35
abstract class Matchers
36
{
37
38
    /**
39
     * Matches a list of Messages if a list containing their respective payloads matches the given
40
     * <code>matcher</code>.
41
     *
42
     * @param Matcher $matcher The mather to match against the Message payloads
43
     * @return Matcher that matches against the Message payloads
44
     */
45 2
    public static function payloadsMatching(Matcher $matcher)
46
    {
47 2
        return new PayloadsMatcher($matcher);
48
    }
49
50
    /**
51
     * Matches a single Message if the given <code>payloadMatcher</code> matches that message's payload.
52
     *
53
     * @param Matcher $payloadMatcher The matcher to match against the Message's payload
54
     * @return Matcher that evaluates a Message's payload.
55
     */
56 1
    public static function messageWithPayload(Matcher $payloadMatcher)
57
    {
58 1
        return new PayloadMatcher($payloadMatcher);
59
    }
60
61
    /**
62
     * Matches a List where all the given matchers must match with at least one of the items in that list.
63
     *
64
     * @param array $matchers the matchers that should match against one of the items in the List.
65
     * @return Matcher a matcher that matches a number of matchers against a list
66
     */
67 5
    public static function listWithAllOf(array $matchers)
68
    {
69 5
        return new ListWithAllOfMatcher($matchers);
70
    }
71
72
    /**
73
     * Matches a List of Events where at least one of the given <code>matchers</code> matches any of the Events in that
74
     * list.
75
     *
76
     * @param array $matchers the matchers that should match against one of the items in the List of Events.
77
     * @return Matcher a matcher that matches a number of event-matchers against a list of events
78
     */
79 7
    public static function listWithAnyOf(array $matchers)
80
    {
81 7
        return new ListWithAnyOfMatcher($matchers);
82
    }
83
84
    /**
85
     * Matches a list of Events if each of the <code>matchers</code> match against an Event that comes after the Event
86
     * that the previous matcher matched against. This means that the given <code>matchers</code> must match in order,
87
     * but there may be "gaps" of unmatched events in between.
88
     * <p/>
89
     * To match the exact sequence of events (i.e. without gaps), use {@link #exactSequenceOf(org.hamcrest.Matcher[])}.
90
     *
91
     * @param array $matchers the matchers to match against the list of events
92
     * @return Matcher a matcher that matches a number of event-matchers against a list of events
93
     */
94 6
    public static function sequenceOf(array $matchers)
95
    {
96 6
        return new SequenceMatcher($matchers);
97
    }
98
99
    /**
100
     * Matches a List of Events if each of the given <code>matchers</code> matches against the event at the respective
101
     * index in the list. This means the first matcher must match the first event, the second matcher the second event,
102
     * and so on.
103
     * <p/>
104
     * Any excess Events are ignored. If there are excess Matchers, they will be evaluated against <code>null</code>.
105
     * To
106
     * make sure the number of Events matches the number of Matchers, you can append an extra {@link #andNoMore()}
107
     * matcher.
108
     * <p/>
109
     * To allow "gaps" of unmatched Events, use {@link #sequenceOf(org.hamcrest.Matcher[])} instead.
110
     *
111
     * @param array $matchers the matchers to match against the list of events
112
     * @return Matcher a matcher that matches a number of event-matchers against a list of events
113
     */
114 10
    public static function exactSequenceOf(array $matchers)
115
    {
116 10
        return new ExactSequenceMatcher($matchers);
117
    }
118
119
    /**
120
     * Matches an empty List of Events.
121
     *
122
     * @return Matcher a matcher that matches an empty list of events
123
     */
124 3
    public static function noEvents()
125
    {
126 3
        return new EmptyCollectionMatcher("events");
127
    }
128
129
    /**
130
     * Matches an empty List of Commands.
131
     *
132
     * @return Matcher a matcher that matches an empty list of Commands
133
     */
134 1
    public static function noCommands()
135
    {
136 1
        return new EmptyCollectionMatcher("commands");
137
    }
138
139
    /**
140
     * Matches against each event of the same runtime type that has all field values equal to the fields in the
141
     * expected
142
     * event. All fields are compared, except for the aggregate identifier and sequence number, as they are generally
143
     * not set on the expected event.
144
     *
145
     * @param mixed $expected The event with the expected field values     
146
     * @return Matcher a matcher that matches based on the equality of field values
147
     */
148 8
    public static function equalTo($expected)
149
    {
150 8
        return new EqualFieldsMatcher($expected);
151
    }
152
153
    /**
154
     * Matches against <code>null</code> or <code>void</code>. Can be used to make sure no trailing events remain when
155
     * using an Exact Sequence Matcher ({@link #exactSequenceOf(org.hamcrest.Matcher[])}).
156
     *
157
     * @return Matcher a matcher that matches against "nothing".
158
     */
159 2
    public static function andNoMore()
160
    {
161 2
        return self::nothing();
162
    }
163
164
    /**
165
     * Matches against <code>null</code> or <code>void</code>. Can be used to make sure no trailing events remain when
166
     * using an Exact Sequence Matcher ({@link #exactSequenceOf(org.hamcrest.Matcher[])}).
167
     *
168
     * @return Matcher a matcher that matches against "nothing".
169
     */
170 3
    public static function nothing()
171
    {
172 3
        return new NullOrVoidMatcher();
173
    }
174
175
}
176