@@ 93-111 (lines=19) @@ | ||
90 | static::assertSame($second, $collection->last()); |
|
91 | } |
|
92 | ||
93 | public function testFirstWithCallbackWillReturnTheFirstThatMatches() |
|
94 | { |
|
95 | $first = m::mock(NodeInterface::class); |
|
96 | $second = m::mock(NodeInterface::class); |
|
97 | $third = m::mock(NodeInterface::class); |
|
98 | ||
99 | $first->shouldReceive('thisOne') |
|
100 | ->andReturn(false); |
|
101 | $second->shouldReceive('thisOne') |
|
102 | ->andReturn(true); |
|
103 | $third->shouldReceive('thosOne') |
|
104 | ->andReturn(true); |
|
105 | ||
106 | $collection = new NodeCollection([$first, $second, $third]); |
|
107 | ||
108 | static::assertSame($second, $collection->first(function ($item) { |
|
109 | return $item->thisOne(); |
|
110 | })); |
|
111 | } |
|
112 | ||
113 | public function testLastWithCallbackWillReturnTheFirstThatMatches() |
|
114 | { |
|
@@ 113-131 (lines=19) @@ | ||
110 | })); |
|
111 | } |
|
112 | ||
113 | public function testLastWithCallbackWillReturnTheFirstThatMatches() |
|
114 | { |
|
115 | $first = m::mock(NodeInterface::class); |
|
116 | $second = m::mock(NodeInterface::class); |
|
117 | $third = m::mock(NodeInterface::class); |
|
118 | ||
119 | $first->shouldReceive('thisOne') |
|
120 | ->andReturn(true); |
|
121 | $second->shouldReceive('thisOne') |
|
122 | ->andReturn(true); |
|
123 | $third->shouldReceive('thisOne') |
|
124 | ->andReturn(false); |
|
125 | ||
126 | $collection = new NodeCollection([$first, $second, $third]); |
|
127 | ||
128 | static::assertSame($second, $collection->last(function ($item) { |
|
129 | return $item->thisOne(); |
|
130 | })); |
|
131 | } |
|
132 | ||
133 | public function testFirstWithCallbackWillReturnDefaultIfNoMatchesAreFound() |
|
134 | { |
|
@@ 133-152 (lines=20) @@ | ||
130 | })); |
|
131 | } |
|
132 | ||
133 | public function testFirstWithCallbackWillReturnDefaultIfNoMatchesAreFound() |
|
134 | { |
|
135 | $first = m::mock(NodeInterface::class); |
|
136 | $second = m::mock(NodeInterface::class); |
|
137 | $default = m::mock(NodeInterface::class); |
|
138 | ||
139 | $first->shouldReceive('thisOne') |
|
140 | ->andReturn(false); |
|
141 | $second->shouldReceive('thisOne') |
|
142 | ->andReturn(false); |
|
143 | ||
144 | $collection = new NodeCollection([$first, $second]); |
|
145 | ||
146 | static::assertSame($default, $collection->first(function ($item) { |
|
147 | return $item->thisOne(); |
|
148 | }, $default)); |
|
149 | static::assertNull($collection->first(function ($item) { |
|
150 | return $item->thisOne(); |
|
151 | })); |
|
152 | } |
|
153 | ||
154 | public function testLastWithCallbackWillReturnDefaultIfNoMatchesAreFound() |
|
155 | { |
|
@@ 154-173 (lines=20) @@ | ||
151 | })); |
|
152 | } |
|
153 | ||
154 | public function testLastWithCallbackWillReturnDefaultIfNoMatchesAreFound() |
|
155 | { |
|
156 | $first = m::mock(NodeInterface::class); |
|
157 | $second = m::mock(NodeInterface::class); |
|
158 | $default = m::mock(NodeInterface::class); |
|
159 | ||
160 | $first->shouldReceive('thisOne') |
|
161 | ->andReturn(false); |
|
162 | $second->shouldReceive('thisOne') |
|
163 | ->andReturn(false); |
|
164 | ||
165 | $collection = new NodeCollection([$first, $second]); |
|
166 | ||
167 | static::assertSame($default, $collection->last(function ($item) { |
|
168 | return $item->thisOne(); |
|
169 | }, $default)); |
|
170 | static::assertNull($collection->last(function ($item) { |
|
171 | return $item->thisOne(); |
|
172 | })); |
|
173 | } |
|
174 | ||
175 | public function testCloneWillCloneTheChildObjects() |
|
176 | { |