@@ -14,364 +14,364 @@ discard block |
||
14 | 14 | { |
15 | 15 | public function testClear() |
16 | 16 | { |
17 | - $c = new Map(['foo', 'bar']); |
|
18 | - $this->assertCount(0, $c->clear()); |
|
17 | + $c = new Map( ['foo', 'bar'] ); |
|
18 | + $this->assertCount( 0, $c->clear() ); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | public function testCopy() |
22 | 22 | { |
23 | - $c = new Map(['foo', 'bar']); |
|
23 | + $c = new Map( ['foo', 'bar'] ); |
|
24 | 24 | $cp = $c->copy(); |
25 | 25 | $c->clear(); |
26 | - $this->assertCount(2, $cp); |
|
26 | + $this->assertCount( 2, $cp ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | public function testFirstReturnsFirstItemInMap() |
30 | 30 | { |
31 | - $c = new Map(['foo', 'bar']); |
|
32 | - $this->assertEquals('foo', $c->first()); |
|
31 | + $c = new Map( ['foo', 'bar'] ); |
|
32 | + $this->assertEquals( 'foo', $c->first() ); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | public function testFirstWithCallback() |
36 | 36 | { |
37 | - $data = new Map(['foo', 'bar', 'baz']); |
|
37 | + $data = new Map( ['foo', 'bar', 'baz'] ); |
|
38 | 38 | $result = $data->first( function( $value ) { |
39 | 39 | return $value === 'bar'; |
40 | 40 | } ); |
41 | - $this->assertEquals('bar', $result); |
|
41 | + $this->assertEquals( 'bar', $result ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | public function testFirstWithCallbackAndDefault() |
45 | 45 | { |
46 | - $data = new Map(['foo', 'bar']); |
|
46 | + $data = new Map( ['foo', 'bar'] ); |
|
47 | 47 | $result = $data->first( function( $value ) { |
48 | 48 | return $value === 'baz'; |
49 | 49 | }, 'default' ); |
50 | - $this->assertEquals('default', $result); |
|
50 | + $this->assertEquals( 'default', $result ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | public function testFirstWithDefaultAndWithoutCallback() |
54 | 54 | { |
55 | 55 | $data = new Map; |
56 | - $result = $data->first(null, 'default'); |
|
57 | - $this->assertEquals('default', $result); |
|
56 | + $result = $data->first( null, 'default' ); |
|
57 | + $this->assertEquals( 'default', $result ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public function testLastReturnsLastItemInMap() |
61 | 61 | { |
62 | - $c = new Map(['foo', 'bar']); |
|
63 | - $this->assertEquals('bar', $c->last()); |
|
62 | + $c = new Map( ['foo', 'bar'] ); |
|
63 | + $this->assertEquals( 'bar', $c->last() ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | public function testLastWithCallback() |
67 | 67 | { |
68 | - $data = new Map([100, 200, 300]); |
|
68 | + $data = new Map( [100, 200, 300] ); |
|
69 | 69 | $result = $data->last( function( $value ) { |
70 | 70 | return $value < 250; |
71 | 71 | } ); |
72 | - $this->assertEquals(200, $result); |
|
72 | + $this->assertEquals( 200, $result ); |
|
73 | 73 | $result = $data->last( function( $value, $key ) { |
74 | 74 | return $key < 2; |
75 | 75 | } ); |
76 | - $this->assertEquals(200, $result); |
|
76 | + $this->assertEquals( 200, $result ); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | public function testLastWithCallbackAndDefault() |
80 | 80 | { |
81 | - $data = new Map(['foo', 'bar']); |
|
81 | + $data = new Map( ['foo', 'bar'] ); |
|
82 | 82 | $result = $data->last( function( $value ) { |
83 | 83 | return $value === 'baz'; |
84 | 84 | }, 'default' ); |
85 | - $this->assertEquals('default', $result); |
|
85 | + $this->assertEquals( 'default', $result ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | public function testLastWithDefaultAndWithoutCallback() |
89 | 89 | { |
90 | 90 | $data = new Map; |
91 | - $result = $data->last(null, 'default'); |
|
92 | - $this->assertEquals('default', $result); |
|
91 | + $result = $data->last( null, 'default' ); |
|
92 | + $this->assertEquals( 'default', $result ); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | public function testPopReturnsAndRemovesLastItemInMap() |
96 | 96 | { |
97 | - $c = new Map(['foo', 'bar']); |
|
97 | + $c = new Map( ['foo', 'bar'] ); |
|
98 | 98 | |
99 | - $this->assertEquals('bar', $c->pop()); |
|
100 | - $this->assertEquals('foo', $c->first()); |
|
99 | + $this->assertEquals( 'bar', $c->pop() ); |
|
100 | + $this->assertEquals( 'foo', $c->first() ); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | public function testShiftReturnsAndRemovesFirstItemInMap() |
104 | 104 | { |
105 | - $c = new Map(['foo', 'bar']); |
|
105 | + $c = new Map( ['foo', 'bar'] ); |
|
106 | 106 | |
107 | - $this->assertEquals('foo', $c->shift()); |
|
108 | - $this->assertEquals('bar', $c->first()); |
|
107 | + $this->assertEquals( 'foo', $c->shift() ); |
|
108 | + $this->assertEquals( 'bar', $c->first() ); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | public function testEmptyMapIsEmpty() |
112 | 112 | { |
113 | 113 | $c = new Map; |
114 | 114 | |
115 | - $this->assertTrue($c->isEmpty()); |
|
115 | + $this->assertTrue( $c->isEmpty() ); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | public function testMapIsConstructed() |
119 | 119 | { |
120 | 120 | $map = new Map; |
121 | - $this->assertEmpty($map->toArray()); |
|
121 | + $this->assertEmpty( $map->toArray() ); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | public function testMapShuffle() |
125 | 125 | { |
126 | - $map = new Map(range(0, 100, 10)); |
|
126 | + $map = new Map( range( 0, 100, 10 ) ); |
|
127 | 127 | |
128 | 128 | $firstRandom = $map->copy()->shuffle(); |
129 | 129 | $secondRandom = $map->copy()->shuffle(); |
130 | 130 | |
131 | - $this->assertNotEquals($firstRandom, $secondRandom); |
|
131 | + $this->assertNotEquals( $firstRandom, $secondRandom ); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | public function testGetArray() |
135 | 135 | { |
136 | 136 | $map = new Map; |
137 | 137 | |
138 | - $class = new \ReflectionClass($map); |
|
139 | - $method = $class->getMethod('getArray'); |
|
140 | - $method->setAccessible(true); |
|
138 | + $class = new \ReflectionClass( $map ); |
|
139 | + $method = $class->getMethod( 'getArray' ); |
|
140 | + $method->setAccessible( true ); |
|
141 | 141 | |
142 | - $items = new \ArrayIterator( ['foo' => 'bar']); |
|
143 | - $array = $method->invokeArgs($map, [$items]); |
|
144 | - $this->assertSame(['foo' => 'bar'], $array); |
|
142 | + $items = new \ArrayIterator( ['foo' => 'bar'] ); |
|
143 | + $array = $method->invokeArgs( $map, [$items] ); |
|
144 | + $this->assertSame( ['foo' => 'bar'], $array ); |
|
145 | 145 | |
146 | - $items = new Map(['foo' => 'bar']); |
|
147 | - $array = $method->invokeArgs($map, [$items]); |
|
148 | - $this->assertSame(['foo' => 'bar'], $array); |
|
146 | + $items = new Map( ['foo' => 'bar'] ); |
|
147 | + $array = $method->invokeArgs( $map, [$items] ); |
|
148 | + $this->assertSame( ['foo' => 'bar'], $array ); |
|
149 | 149 | |
150 | 150 | $items = ['foo' => 'bar']; |
151 | - $array = $method->invokeArgs($map, [$items]); |
|
152 | - $this->assertSame(['foo' => 'bar'], $array); |
|
151 | + $array = $method->invokeArgs( $map, [$items] ); |
|
152 | + $this->assertSame( ['foo' => 'bar'], $array ); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | public function testOffsetAccess() |
156 | 156 | { |
157 | - $c = new Map(['name' => 'test']); |
|
158 | - $this->assertEquals('test', $c['name']); |
|
157 | + $c = new Map( ['name' => 'test'] ); |
|
158 | + $this->assertEquals( 'test', $c['name'] ); |
|
159 | 159 | $c['name'] = 'me'; |
160 | - $this->assertEquals('me', $c['name']); |
|
161 | - $this->assertTrue(isset($c['name'])); |
|
162 | - unset($c['name']); |
|
163 | - $this->assertFalse(isset($c['name'])); |
|
160 | + $this->assertEquals( 'me', $c['name'] ); |
|
161 | + $this->assertTrue( isset( $c['name'] ) ); |
|
162 | + unset( $c['name'] ); |
|
163 | + $this->assertFalse( isset( $c['name'] ) ); |
|
164 | 164 | $c[] = 'jason'; |
165 | - $this->assertEquals('jason', $c[0]); |
|
165 | + $this->assertEquals( 'jason', $c[0] ); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | public function testArrayAccessOffsetExists() |
169 | 169 | { |
170 | - $c = new Map(['foo', 'bar']); |
|
171 | - $this->assertTrue($c->offsetExists(0)); |
|
172 | - $this->assertTrue($c->offsetExists(1)); |
|
173 | - $this->assertFalse($c->offsetExists(1000)); |
|
170 | + $c = new Map( ['foo', 'bar'] ); |
|
171 | + $this->assertTrue( $c->offsetExists( 0 ) ); |
|
172 | + $this->assertTrue( $c->offsetExists( 1 ) ); |
|
173 | + $this->assertFalse( $c->offsetExists( 1000 ) ); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | public function testArrayAccessOffsetGet() |
177 | 177 | { |
178 | - $c = new Map(['foo', 'bar']); |
|
179 | - $this->assertEquals('foo', $c->offsetGet(0)); |
|
180 | - $this->assertEquals('bar', $c->offsetGet(1)); |
|
178 | + $c = new Map( ['foo', 'bar'] ); |
|
179 | + $this->assertEquals( 'foo', $c->offsetGet( 0 ) ); |
|
180 | + $this->assertEquals( 'bar', $c->offsetGet( 1 ) ); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | public function testArrayAccessOffsetSet() |
184 | 184 | { |
185 | - $c = new Map(['foo', 'foo']); |
|
185 | + $c = new Map( ['foo', 'foo'] ); |
|
186 | 186 | |
187 | - $c->offsetSet(1, 'bar'); |
|
188 | - $this->assertEquals('bar', $c[1]); |
|
187 | + $c->offsetSet( 1, 'bar' ); |
|
188 | + $this->assertEquals( 'bar', $c[1] ); |
|
189 | 189 | |
190 | - $c->offsetSet(null, 'qux'); |
|
191 | - $this->assertEquals('qux', $c[2]); |
|
190 | + $c->offsetSet( null, 'qux' ); |
|
191 | + $this->assertEquals( 'qux', $c[2] ); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | public function testArrayAccessOffsetUnset() |
195 | 195 | { |
196 | - $c = new Map(['foo', 'bar']); |
|
196 | + $c = new Map( ['foo', 'bar'] ); |
|
197 | 197 | |
198 | - $c->offsetUnset(1); |
|
199 | - $this->assertFalse(isset($c[1])); |
|
198 | + $c->offsetUnset( 1 ); |
|
199 | + $this->assertFalse( isset( $c[1] ) ); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | public function testRemoveSingleKey() |
203 | 203 | { |
204 | - $c = new Map(['foo', 'bar']); |
|
205 | - $c->remove(0); |
|
206 | - $this->assertFalse(isset($c['foo'])); |
|
204 | + $c = new Map( ['foo', 'bar'] ); |
|
205 | + $c->remove( 0 ); |
|
206 | + $this->assertFalse( isset( $c['foo'] ) ); |
|
207 | 207 | |
208 | - $c = new Map(['foo' => 'bar', 'baz' => 'qux']); |
|
209 | - $c->remove('foo'); |
|
210 | - $this->assertFalse(isset($c['foo'])); |
|
208 | + $c = new Map( ['foo' => 'bar', 'baz' => 'qux'] ); |
|
209 | + $c->remove( 'foo' ); |
|
210 | + $this->assertFalse( isset( $c['foo'] ) ); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | public function testRemoveArrayOfKeys() |
214 | 214 | { |
215 | - $c = new Map(['foo', 'bar', 'baz']); |
|
216 | - $c->remove([0, 2]); |
|
217 | - $this->assertFalse(isset($c[0])); |
|
218 | - $this->assertFalse(isset($c[2])); |
|
219 | - $this->assertTrue(isset($c[1])); |
|
215 | + $c = new Map( ['foo', 'bar', 'baz'] ); |
|
216 | + $c->remove( [0, 2] ); |
|
217 | + $this->assertFalse( isset( $c[0] ) ); |
|
218 | + $this->assertFalse( isset( $c[2] ) ); |
|
219 | + $this->assertTrue( isset( $c[1] ) ); |
|
220 | 220 | |
221 | - $c = new Map(['name' => 'test', 'foo' => 'bar', 'baz' => 'qux']); |
|
222 | - $c->remove(['foo', 'baz']); |
|
223 | - $this->assertFalse(isset($c['foo'])); |
|
224 | - $this->assertFalse(isset($c['baz'])); |
|
225 | - $this->assertTrue(isset($c['name'])); |
|
221 | + $c = new Map( ['name' => 'test', 'foo' => 'bar', 'baz' => 'qux'] ); |
|
222 | + $c->remove( ['foo', 'baz'] ); |
|
223 | + $this->assertFalse( isset( $c['foo'] ) ); |
|
224 | + $this->assertFalse( isset( $c['baz'] ) ); |
|
225 | + $this->assertTrue( isset( $c['name'] ) ); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | public function testCountable() |
229 | 229 | { |
230 | - $c = new Map(['foo', 'bar']); |
|
231 | - $this->assertCount(2, $c); |
|
230 | + $c = new Map( ['foo', 'bar'] ); |
|
231 | + $this->assertCount( 2, $c ); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | public function testIterable() |
235 | 235 | { |
236 | - $c = new Map(['foo']); |
|
237 | - $this->assertInstanceOf(\ArrayIterator::class, $c->getIterator()); |
|
238 | - $this->assertEquals(['foo'], $c->getIterator()->getArrayCopy()); |
|
236 | + $c = new Map( ['foo'] ); |
|
237 | + $this->assertInstanceOf( \ArrayIterator::class, $c->getIterator() ); |
|
238 | + $this->assertEquals( ['foo'], $c->getIterator()->getArrayCopy() ); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | public function testFilter() |
242 | 242 | { |
243 | - $c = new Map([['id' => 1, 'name' => 'Hello'], ['id' => 2, 'name' => 'World']]); |
|
244 | - $this->assertEquals([1 => ['id' => 2, 'name' => 'World']], $c->filter( function( $item ) { |
|
243 | + $c = new Map( [['id' => 1, 'name' => 'Hello'], ['id' => 2, 'name' => 'World']] ); |
|
244 | + $this->assertEquals( [1 => ['id' => 2, 'name' => 'World']], $c->filter( function( $item ) { |
|
245 | 245 | return $item['id'] == 2; |
246 | - } )->toArray()); |
|
246 | + } )->toArray() ); |
|
247 | 247 | |
248 | - $c = new Map(['', 'Hello', '', 'World']); |
|
249 | - $this->assertEquals(['Hello', 'World'], $c->filter()->values()->toArray()); |
|
248 | + $c = new Map( ['', 'Hello', '', 'World'] ); |
|
249 | + $this->assertEquals( ['Hello', 'World'], $c->filter()->values()->toArray() ); |
|
250 | 250 | |
251 | - $c = new Map(['id' => 1, 'first' => 'Hello', 'second' => 'World']); |
|
252 | - $this->assertEquals(['first' => 'Hello', 'second' => 'World'], $c->filter( function( $item, $key ) { |
|
251 | + $c = new Map( ['id' => 1, 'first' => 'Hello', 'second' => 'World'] ); |
|
252 | + $this->assertEquals( ['first' => 'Hello', 'second' => 'World'], $c->filter( function( $item, $key ) { |
|
253 | 253 | return $key != 'id'; |
254 | - } )->toArray()); |
|
254 | + } )->toArray() ); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | public function testValues() |
258 | 258 | { |
259 | - $c = new Map([['id' => 1, 'name' => 'Hello'], ['id' => 2, 'name' => 'World']]); |
|
260 | - $this->assertEquals([['id' => 2, 'name' => 'World']], $c->filter( function( $item ) { |
|
259 | + $c = new Map( [['id' => 1, 'name' => 'Hello'], ['id' => 2, 'name' => 'World']] ); |
|
260 | + $this->assertEquals( [['id' => 2, 'name' => 'World']], $c->filter( function( $item ) { |
|
261 | 261 | return $item['id'] == 2; |
262 | - } )->values()->toArray()); |
|
262 | + } )->values()->toArray() ); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | public function testMergeArray() |
266 | 266 | { |
267 | - $c = new Map(['name' => 'Hello']); |
|
268 | - $this->assertEquals(['name' => 'Hello', 'id' => 1], $c->merge(['id' => 1])->toArray()); |
|
267 | + $c = new Map( ['name' => 'Hello'] ); |
|
268 | + $this->assertEquals( ['name' => 'Hello', 'id' => 1], $c->merge( ['id' => 1] )->toArray() ); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | public function testMergeMap() |
272 | 272 | { |
273 | - $c = new Map(['name' => 'Hello']); |
|
274 | - $this->assertEquals(['name' => 'World', 'id' => 1], $c->merge(new Map(['name' => 'World', 'id' => 1]))->toArray()); |
|
273 | + $c = new Map( ['name' => 'Hello'] ); |
|
274 | + $this->assertEquals( ['name' => 'World', 'id' => 1], $c->merge( new Map( ['name' => 'World', 'id' => 1] ) )->toArray() ); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | public function testReplaceArray() |
278 | 278 | { |
279 | - $c = new Map(['a', 'b', 'c']); |
|
280 | - $this->assertEquals(['a', 'd', 'e'], $c->replace([1 => 'd', 2 => 'e'])->toArray()); |
|
279 | + $c = new Map( ['a', 'b', 'c'] ); |
|
280 | + $this->assertEquals( ['a', 'd', 'e'], $c->replace( [1 => 'd', 2 => 'e'] )->toArray() ); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | public function testReplaceMap() |
284 | 284 | { |
285 | - $c = new Map(['a', 'b', 'c']); |
|
285 | + $c = new Map( ['a', 'b', 'c'] ); |
|
286 | 286 | $this->assertEquals( |
287 | 287 | ['a', 'd', 'e'], |
288 | - $c->replace(new Map([1 => 'd', 2 => 'e']))->toArray() |
|
288 | + $c->replace( new Map( [1 => 'd', 2 => 'e'] ) )->toArray() |
|
289 | 289 | ); |
290 | 290 | } |
291 | 291 | |
292 | 292 | public function testReplaceRecursiveArray() |
293 | 293 | { |
294 | - $c = new Map(['a', 'b', ['c', 'd']]); |
|
295 | - $this->assertEquals(['z', 'b', ['c', 'e']], $c->replace(['z', 2 => [1 => 'e']])->toArray()); |
|
294 | + $c = new Map( ['a', 'b', ['c', 'd']] ); |
|
295 | + $this->assertEquals( ['z', 'b', ['c', 'e']], $c->replace( ['z', 2 => [1 => 'e']] )->toArray() ); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | public function testReplaceRecursiveMap() |
299 | 299 | { |
300 | - $c = new Map(['a', 'b', ['c', 'd']]); |
|
300 | + $c = new Map( ['a', 'b', ['c', 'd']] ); |
|
301 | 301 | $this->assertEquals( |
302 | 302 | ['z', 'b', ['c', 'e']], |
303 | - $c->replace(new Map(['z', 2 => [1 => 'e']]))->toArray() |
|
303 | + $c->replace( new Map( ['z', 2 => [1 => 'e']] ) )->toArray() |
|
304 | 304 | ); |
305 | 305 | } |
306 | 306 | |
307 | 307 | public function testUnionArray() |
308 | 308 | { |
309 | - $c = new Map(['name' => 'Hello']); |
|
310 | - $this->assertEquals(['name' => 'Hello', 'id' => 1], $c->union(['id' => 1])->toArray()); |
|
309 | + $c = new Map( ['name' => 'Hello'] ); |
|
310 | + $this->assertEquals( ['name' => 'Hello', 'id' => 1], $c->union( ['id' => 1] )->toArray() ); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | public function testUnionMap() |
314 | 314 | { |
315 | - $c = new Map(['name' => 'Hello']); |
|
316 | - $this->assertEquals(['name' => 'Hello', 'id' => 1], $c->union(new Map(['name' => 'World', 'id' => 1]))->toArray()); |
|
315 | + $c = new Map( ['name' => 'Hello'] ); |
|
316 | + $this->assertEquals( ['name' => 'Hello', 'id' => 1], $c->union( new Map( ['name' => 'World', 'id' => 1] ) )->toArray() ); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | public function testDiffMap() |
320 | 320 | { |
321 | - $c = new Map(['id' => 1, 'first_word' => 'Hello']); |
|
322 | - $this->assertEquals(['id' => 1], $c->diff(new Map(['first_word' => 'Hello', 'last_word' => 'World']))->toArray()); |
|
321 | + $c = new Map( ['id' => 1, 'first_word' => 'Hello'] ); |
|
322 | + $this->assertEquals( ['id' => 1], $c->diff( new Map( ['first_word' => 'Hello', 'last_word' => 'World'] ) )->toArray() ); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | public function testDiffUsingWithMap() |
326 | 326 | { |
327 | - $c = new Map(['en_GB', 'fr', 'HR']); |
|
327 | + $c = new Map( ['en_GB', 'fr', 'HR'] ); |
|
328 | 328 | // demonstrate that diffKeys wont support case insensitivity |
329 | - $this->assertEquals(['en_GB', 'fr', 'HR'], $c->diff(new Map(['en_gb', 'hr']))->values()->toArray()); |
|
329 | + $this->assertEquals( ['en_GB', 'fr', 'HR'], $c->diff( new Map( ['en_gb', 'hr'] ) )->values()->toArray() ); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | public function testDiffKeys() |
333 | 333 | { |
334 | - $c1 = new Map(['id' => 1, 'first_word' => 'Hello']); |
|
335 | - $c2 = new Map(['id' => 123, 'foo_bar' => 'Hello']); |
|
336 | - $this->assertEquals(['first_word' => 'Hello'], $c1->diffKeys($c2)->toArray()); |
|
334 | + $c1 = new Map( ['id' => 1, 'first_word' => 'Hello'] ); |
|
335 | + $c2 = new Map( ['id' => 123, 'foo_bar' => 'Hello'] ); |
|
336 | + $this->assertEquals( ['first_word' => 'Hello'], $c1->diffKeys( $c2 )->toArray() ); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | public function testDiffKeysFunction() |
340 | 340 | { |
341 | - $c1 = new Map(['id' => 1, 'first_word' => 'Hello']); |
|
342 | - $c2 = new Map(['ID' => 123, 'foo_bar' => 'Hello']); |
|
341 | + $c1 = new Map( ['id' => 1, 'first_word' => 'Hello'] ); |
|
342 | + $c2 = new Map( ['ID' => 123, 'foo_bar' => 'Hello'] ); |
|
343 | 343 | // demonstrate that diffKeys wont support case insensitivity |
344 | - $this->assertEquals(['id'=>1, 'first_word'=> 'Hello'], $c1->diffKeys($c2)->toArray()); |
|
344 | + $this->assertEquals( ['id'=>1, 'first_word'=> 'Hello'], $c1->diffKeys( $c2 )->toArray() ); |
|
345 | 345 | // allow for case insensitive difference |
346 | - $this->assertEquals(['first_word' => 'Hello'], $c1->diffKeys($c2, 'strcasecmp')->toArray()); |
|
346 | + $this->assertEquals( ['first_word' => 'Hello'], $c1->diffKeys( $c2, 'strcasecmp' )->toArray() ); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | public function testDiffAssoc() |
350 | 350 | { |
351 | - $c1 = new Map(['id' => 1, 'first_word' => 'Hello', 'not_affected' => 'value']); |
|
352 | - $c2 = new Map(['id' => 123, 'foo_bar' => 'Hello', 'not_affected' => 'value']); |
|
353 | - $this->assertEquals(['id' => 1, 'first_word' => 'Hello'], $c1->diffAssoc($c2)->toArray()); |
|
351 | + $c1 = new Map( ['id' => 1, 'first_word' => 'Hello', 'not_affected' => 'value'] ); |
|
352 | + $c2 = new Map( ['id' => 123, 'foo_bar' => 'Hello', 'not_affected' => 'value'] ); |
|
353 | + $this->assertEquals( ['id' => 1, 'first_word' => 'Hello'], $c1->diffAssoc( $c2 )->toArray() ); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | public function testDiffAssocFunction() |
357 | 357 | { |
358 | - $c1 = new Map(['a' => 'green', 'b' => 'brown', 'c' => 'blue', 'red']); |
|
359 | - $c2 = new Map(['A' => 'green', 'yellow', 'red']); |
|
358 | + $c1 = new Map( ['a' => 'green', 'b' => 'brown', 'c' => 'blue', 'red'] ); |
|
359 | + $c2 = new Map( ['A' => 'green', 'yellow', 'red'] ); |
|
360 | 360 | // demonstrate that the case of the keys will affect the output when diffAssoc is used |
361 | - $this->assertEquals(['a' => 'green', 'b' => 'brown', 'c' => 'blue', 'red'], $c1->diffAssoc($c2)->toArray()); |
|
361 | + $this->assertEquals( ['a' => 'green', 'b' => 'brown', 'c' => 'blue', 'red'], $c1->diffAssoc( $c2 )->toArray() ); |
|
362 | 362 | // allow for case insensitive difference |
363 | - $this->assertEquals(['b' => 'brown', 'c' => 'blue', 'red'], $c1->diffAssoc($c2, 'strcasecmp')->toArray()); |
|
363 | + $this->assertEquals( ['b' => 'brown', 'c' => 'blue', 'red'], $c1->diffAssoc( $c2, 'strcasecmp' )->toArray() ); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | public function testEach() |
367 | 367 | { |
368 | - $c = new Map($original = [1, 2, 'foo' => 'bar', 'bam' => 'baz']); |
|
368 | + $c = new Map( $original = [1, 2, 'foo' => 'bar', 'bam' => 'baz'] ); |
|
369 | 369 | |
370 | 370 | $result = []; |
371 | 371 | $c->each( function( $item, $key ) use ( &$result ) { |
372 | 372 | $result[$key] = $item; |
373 | 373 | } ); |
374 | - $this->assertEquals($original, $result); |
|
374 | + $this->assertEquals( $original, $result ); |
|
375 | 375 | |
376 | 376 | $result = []; |
377 | 377 | $c->each( function( $item, $key ) use ( &$result ) { |
@@ -380,196 +380,196 @@ discard block |
||
380 | 380 | return false; |
381 | 381 | } |
382 | 382 | } ); |
383 | - $this->assertEquals([1, 2, 'foo' => 'bar'], $result); |
|
383 | + $this->assertEquals( [1, 2, 'foo' => 'bar'], $result ); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | public function testIntersectMap() |
387 | 387 | { |
388 | - $c = new Map(['id' => 1, 'first_word' => 'Hello']); |
|
389 | - $this->assertEquals(['first_word' => 'Hello'], $c->intersect(new Map(['first_world' => 'Hello', 'last_word' => 'World']))->toArray()); |
|
388 | + $c = new Map( ['id' => 1, 'first_word' => 'Hello'] ); |
|
389 | + $this->assertEquals( ['first_word' => 'Hello'], $c->intersect( new Map( ['first_world' => 'Hello', 'last_word' => 'World'] ) )->toArray() ); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | public function testIntersectKeys() |
393 | 393 | { |
394 | - $c = new Map(['name' => 'Mateus', 'age' => 18]); |
|
395 | - $this->assertEquals(['name' => 'Mateus'], $c->intersectKeys(new Map(['name' => 'Mateus', 'surname' => 'Guimaraes']))->toArray()); |
|
394 | + $c = new Map( ['name' => 'Mateus', 'age' => 18] ); |
|
395 | + $this->assertEquals( ['name' => 'Mateus'], $c->intersectKeys( new Map( ['name' => 'Mateus', 'surname' => 'Guimaraes'] ) )->toArray() ); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | public function testUnique() |
399 | 399 | { |
400 | - $c = new Map(['Hello', 'World', 'World']); |
|
401 | - $this->assertEquals(['Hello', 'World'], $c->unique()->toArray()); |
|
400 | + $c = new Map( ['Hello', 'World', 'World'] ); |
|
401 | + $this->assertEquals( ['Hello', 'World'], $c->unique()->toArray() ); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | public function testSort() |
405 | 405 | { |
406 | - $data = (new Map([5, 3, 1, 2, 4]))->sort(); |
|
407 | - $this->assertEquals([1, 2, 3, 4, 5], $data->values()->toArray()); |
|
406 | + $data = ( new Map( [5, 3, 1, 2, 4] ) )->sort(); |
|
407 | + $this->assertEquals( [1, 2, 3, 4, 5], $data->values()->toArray() ); |
|
408 | 408 | |
409 | - $data = (new Map([-1, -3, -2, -4, -5, 0, 5, 3, 1, 2, 4]))->sort(); |
|
410 | - $this->assertEquals([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], $data->values()->toArray()); |
|
409 | + $data = ( new Map( [-1, -3, -2, -4, -5, 0, 5, 3, 1, 2, 4] ) )->sort(); |
|
410 | + $this->assertEquals( [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], $data->values()->toArray() ); |
|
411 | 411 | |
412 | - $data = (new Map(['foo', 'bar-10', 'bar-1']))->sort(); |
|
413 | - $this->assertEquals(['bar-1', 'bar-10', 'foo'], $data->values()->toArray()); |
|
412 | + $data = ( new Map( ['foo', 'bar-10', 'bar-1'] ) )->sort(); |
|
413 | + $this->assertEquals( ['bar-1', 'bar-10', 'foo'], $data->values()->toArray() ); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | public function testKsort() |
417 | 417 | { |
418 | - $data = new Map(['b' => 'me', 'a' => 'test']); |
|
418 | + $data = new Map( ['b' => 'me', 'a' => 'test'] ); |
|
419 | 419 | |
420 | - $this->assertSame(['a' => 'test', 'b' => 'me'], $data->ksort()->toArray()); |
|
420 | + $this->assertSame( ['a' => 'test', 'b' => 'me'], $data->ksort()->toArray() ); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | public function testReverse() |
424 | 424 | { |
425 | - $data = new Map(['hello', 'world']); |
|
425 | + $data = new Map( ['hello', 'world'] ); |
|
426 | 426 | $reversed = $data->reverse(); |
427 | 427 | |
428 | - $this->assertSame([1 => 'world', 0 => 'hello'], $reversed->toArray()); |
|
428 | + $this->assertSame( [1 => 'world', 0 => 'hello'], $reversed->toArray() ); |
|
429 | 429 | |
430 | - $data = new Map(['name' => 'test', 'last' => 'user']); |
|
430 | + $data = new Map( ['name' => 'test', 'last' => 'user'] ); |
|
431 | 431 | $reversed = $data->reverse(); |
432 | 432 | |
433 | - $this->assertSame(['last' => 'user', 'name' => 'test'], $reversed->toArray()); |
|
433 | + $this->assertSame( ['last' => 'user', 'name' => 'test'], $reversed->toArray() ); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | public function testHas() |
437 | 437 | { |
438 | - $data = new Map(['id' => 1, 'first' => 'Hello', 'second' => 'World']); |
|
439 | - $this->assertTrue($data->has('first')); |
|
440 | - $this->assertFalse($data->has('third')); |
|
438 | + $data = new Map( ['id' => 1, 'first' => 'Hello', 'second' => 'World'] ); |
|
439 | + $this->assertTrue( $data->has( 'first' ) ); |
|
440 | + $this->assertFalse( $data->has( 'third' ) ); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | public function testMethod() |
444 | 444 | { |
445 | - Map::method('foo', function() { |
|
445 | + Map::method( 'foo', function() { |
|
446 | 446 | return $this->filter( function( $item ) { |
447 | - return strpos($item, 'a') === 0; |
|
447 | + return strpos( $item, 'a' ) === 0; |
|
448 | 448 | }) |
449 | 449 | ->unique() |
450 | 450 | ->values(); |
451 | 451 | } ); |
452 | 452 | |
453 | - $c = new Map(['a', 'a', 'aa', 'aaa', 'bar']); |
|
453 | + $c = new Map( ['a', 'a', 'aa', 'aaa', 'bar'] ); |
|
454 | 454 | |
455 | - $this->assertSame(['a', 'aa', 'aaa'], $c->foo()->toArray()); |
|
455 | + $this->assertSame( ['a', 'aa', 'aaa'], $c->foo()->toArray() ); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | public function testMakeMethodFromMap() |
459 | 459 | { |
460 | - $firstMap = Map::from(['foo' => 'bar']); |
|
461 | - $secondMap = Map::from($firstMap); |
|
462 | - $this->assertEquals(['foo' => 'bar'], $secondMap->toArray()); |
|
460 | + $firstMap = Map::from( ['foo' => 'bar'] ); |
|
461 | + $secondMap = Map::from( $firstMap ); |
|
462 | + $this->assertEquals( ['foo' => 'bar'], $secondMap->toArray() ); |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | public function testMakeMethodFromArray() |
466 | 466 | { |
467 | - $map = Map::from(['foo' => 'bar']); |
|
468 | - $this->assertEquals(['foo' => 'bar'], $map->toArray()); |
|
467 | + $map = Map::from( ['foo' => 'bar'] ); |
|
468 | + $this->assertEquals( ['foo' => 'bar'], $map->toArray() ); |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | public function testConstructMethodFromMap() |
472 | 472 | { |
473 | - $firstMap = new Map(['foo' => 'bar']); |
|
474 | - $secondMap = new Map($firstMap); |
|
475 | - $this->assertEquals(['foo' => 'bar'], $secondMap->toArray()); |
|
473 | + $firstMap = new Map( ['foo' => 'bar'] ); |
|
474 | + $secondMap = new Map( $firstMap ); |
|
475 | + $this->assertEquals( ['foo' => 'bar'], $secondMap->toArray() ); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | public function testConstructMethodFromArray() |
479 | 479 | { |
480 | - $map = new Map(['foo' => 'bar']); |
|
481 | - $this->assertEquals(['foo' => 'bar'], $map->toArray()); |
|
480 | + $map = new Map( ['foo' => 'bar'] ); |
|
481 | + $this->assertEquals( ['foo' => 'bar'], $map->toArray() ); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | public function testSplice() |
485 | 485 | { |
486 | - $data = new Map(['foo', 'baz']); |
|
487 | - $data->splice(1); |
|
488 | - $this->assertEquals(['foo'], $data->toArray()); |
|
486 | + $data = new Map( ['foo', 'baz'] ); |
|
487 | + $data->splice( 1 ); |
|
488 | + $this->assertEquals( ['foo'], $data->toArray() ); |
|
489 | 489 | |
490 | - $data = new Map(['foo', 'baz']); |
|
491 | - $data->splice(1, 0, 'bar'); |
|
492 | - $this->assertEquals(['foo', 'bar', 'baz'], $data->toArray()); |
|
490 | + $data = new Map( ['foo', 'baz'] ); |
|
491 | + $data->splice( 1, 0, 'bar' ); |
|
492 | + $this->assertEquals( ['foo', 'bar', 'baz'], $data->toArray() ); |
|
493 | 493 | |
494 | - $data = new Map(['foo', 'baz']); |
|
495 | - $data->splice(1, 1); |
|
496 | - $this->assertEquals(['foo'], $data->toArray()); |
|
494 | + $data = new Map( ['foo', 'baz'] ); |
|
495 | + $data->splice( 1, 1 ); |
|
496 | + $this->assertEquals( ['foo'], $data->toArray() ); |
|
497 | 497 | |
498 | - $data = new Map(['foo', 'baz']); |
|
499 | - $cut = $data->splice(1, 1, 'bar'); |
|
500 | - $this->assertEquals(['foo', 'bar'], $data->toArray()); |
|
501 | - $this->assertEquals(['baz'], $cut->toArray()); |
|
498 | + $data = new Map( ['foo', 'baz'] ); |
|
499 | + $cut = $data->splice( 1, 1, 'bar' ); |
|
500 | + $this->assertEquals( ['foo', 'bar'], $data->toArray() ); |
|
501 | + $this->assertEquals( ['baz'], $cut->toArray() ); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | public function testMap() |
505 | 505 | { |
506 | - $data = new Map(['first' => 'test', 'last' => 'user']); |
|
506 | + $data = new Map( ['first' => 'test', 'last' => 'user'] ); |
|
507 | 507 | $data = $data->map( function( $item, $key ) { |
508 | - return $key.'-'.strrev($item); |
|
508 | + return $key . '-' . strrev( $item ); |
|
509 | 509 | } ); |
510 | - $this->assertEquals(['first' => 'first-tset', 'last' => 'last-resu'], $data->toArray()); |
|
510 | + $this->assertEquals( ['first' => 'first-tset', 'last' => 'last-resu'], $data->toArray() ); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | public function testPullRetrievesItemFromMap() |
514 | 514 | { |
515 | - $c = new Map(['foo', 'bar']); |
|
515 | + $c = new Map( ['foo', 'bar'] ); |
|
516 | 516 | |
517 | - $this->assertEquals('foo', $c->pull(0)); |
|
517 | + $this->assertEquals( 'foo', $c->pull( 0 ) ); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | public function testPullRemovesItemFromMap() |
521 | 521 | { |
522 | - $c = new Map(['foo', 'bar']); |
|
523 | - $c->pull(0); |
|
524 | - $this->assertEquals([1 => 'bar'], $c->toArray()); |
|
522 | + $c = new Map( ['foo', 'bar'] ); |
|
523 | + $c->pull( 0 ); |
|
524 | + $this->assertEquals( [1 => 'bar'], $c->toArray() ); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | public function testPullReturnsDefault() |
528 | 528 | { |
529 | - $c = new Map([]); |
|
530 | - $value = $c->pull(0, 'foo'); |
|
531 | - $this->assertEquals('foo', $value); |
|
529 | + $c = new Map( [] ); |
|
530 | + $value = $c->pull( 0, 'foo' ); |
|
531 | + $this->assertEquals( 'foo', $value ); |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | public function testSearch() |
535 | 535 | { |
536 | - $c = new Map([false, 0, 1, [], '']); |
|
537 | - $this->assertNull($c->search('false')); |
|
538 | - $this->assertNull($c->search('1')); |
|
539 | - $this->assertEquals(0, $c->search(false)); |
|
540 | - $this->assertEquals(1, $c->search(0)); |
|
541 | - $this->assertEquals(2, $c->search(1)); |
|
542 | - $this->assertEquals(3, $c->search([])); |
|
543 | - $this->assertEquals(4, $c->search('')); |
|
536 | + $c = new Map( [false, 0, 1, [], ''] ); |
|
537 | + $this->assertNull( $c->search( 'false' ) ); |
|
538 | + $this->assertNull( $c->search( '1' ) ); |
|
539 | + $this->assertEquals( 0, $c->search( false ) ); |
|
540 | + $this->assertEquals( 1, $c->search( 0 ) ); |
|
541 | + $this->assertEquals( 2, $c->search( 1 ) ); |
|
542 | + $this->assertEquals( 3, $c->search( [] ) ); |
|
543 | + $this->assertEquals( 4, $c->search( '' ) ); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | public function testSearchReturnsNullWhenItemIsNotFound() |
547 | 547 | { |
548 | - $c = new Map([1, 2, 3, 4, 5, 'foo' => 'bar']); |
|
548 | + $c = new Map( [1, 2, 3, 4, 5, 'foo' => 'bar'] ); |
|
549 | 549 | |
550 | - $this->assertNull($c->search(6)); |
|
551 | - $this->assertNull($c->search('foo')); |
|
552 | - $this->assertNull($c->search( function( $value ) { |
|
553 | - return $value < 1 && is_numeric($value); |
|
554 | - } )); |
|
555 | - $this->assertNull($c->search( function( $value ) { |
|
550 | + $this->assertNull( $c->search( 6 ) ); |
|
551 | + $this->assertNull( $c->search( 'foo' ) ); |
|
552 | + $this->assertNull( $c->search( function( $value ) { |
|
553 | + return $value < 1 && is_numeric( $value ); |
|
554 | + } ) ); |
|
555 | + $this->assertNull( $c->search( function( $value ) { |
|
556 | 556 | return $value == 'nope'; |
557 | - } )); |
|
557 | + } ) ); |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | public function testKeys() |
561 | 561 | { |
562 | - $c = new Map(['name' => 'test', 'last' => 'user']); |
|
563 | - $this->assertEquals(['name', 'last'], $c->keys()->toArray()); |
|
562 | + $c = new Map( ['name' => 'test', 'last' => 'user'] ); |
|
563 | + $this->assertEquals( ['name', 'last'], $c->keys()->toArray() ); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | public function testUnshift() |
567 | 567 | { |
568 | - $c = new Map(['one', 'two', 'three', 'four']); |
|
569 | - $this->assertEquals(['zero', 'one', 'two', 'three', 'four'], $c->unshift('zero')->toArray()); |
|
568 | + $c = new Map( ['one', 'two', 'three', 'four'] ); |
|
569 | + $this->assertEquals( ['zero', 'one', 'two', 'three', 'four'], $c->unshift( 'zero' )->toArray() ); |
|
570 | 570 | |
571 | - $c = new Map(['one' => 1, 'two' => 2]); |
|
572 | - $this->assertEquals(['zero' => 0, 'one' => 1, 'two' => 2], $c->unshift(0, 'zero')->toArray()); |
|
571 | + $c = new Map( ['one' => 1, 'two' => 2] ); |
|
572 | + $this->assertEquals( ['zero' => 0, 'one' => 1, 'two' => 2], $c->unshift( 0, 'zero' )->toArray() ); |
|
573 | 573 | } |
574 | 574 | |
575 | 575 | public function testConcatWithArray() |
@@ -589,12 +589,12 @@ discard block |
||
589 | 589 | 11 => 'Laroe', |
590 | 590 | ]; |
591 | 591 | |
592 | - $map = new Map([4, 5, 6]); |
|
593 | - $map = $map->concat(['a', 'b', 'c']); |
|
594 | - $map = $map->concat(['who' => 'Jonny', 'preposition' => 'from', 'where' => 'Laroe']); |
|
595 | - $actual = $map->concat(['who' => 'Jonny', 'preposition' => 'from', 'where' => 'Laroe'])->toArray(); |
|
592 | + $map = new Map( [4, 5, 6] ); |
|
593 | + $map = $map->concat( ['a', 'b', 'c'] ); |
|
594 | + $map = $map->concat( ['who' => 'Jonny', 'preposition' => 'from', 'where' => 'Laroe'] ); |
|
595 | + $actual = $map->concat( ['who' => 'Jonny', 'preposition' => 'from', 'where' => 'Laroe'] )->toArray(); |
|
596 | 596 | |
597 | - $this->assertSame($expected, $actual); |
|
597 | + $this->assertSame( $expected, $actual ); |
|
598 | 598 | } |
599 | 599 | |
600 | 600 | public function testConcatWithMap() |
@@ -614,27 +614,27 @@ discard block |
||
614 | 614 | 11 => 'Laroe', |
615 | 615 | ]; |
616 | 616 | |
617 | - $firstMap = new Map([4, 5, 6]); |
|
618 | - $secondMap = new Map(['a', 'b', 'c']); |
|
619 | - $thirdMap = new Map(['who' => 'Jonny', 'preposition' => 'from', 'where' => 'Laroe']); |
|
620 | - $firstMap = $firstMap->concat($secondMap); |
|
621 | - $firstMap = $firstMap->concat($thirdMap); |
|
622 | - $actual = $firstMap->concat($thirdMap)->toArray(); |
|
617 | + $firstMap = new Map( [4, 5, 6] ); |
|
618 | + $secondMap = new Map( ['a', 'b', 'c'] ); |
|
619 | + $thirdMap = new Map( ['who' => 'Jonny', 'preposition' => 'from', 'where' => 'Laroe'] ); |
|
620 | + $firstMap = $firstMap->concat( $secondMap ); |
|
621 | + $firstMap = $firstMap->concat( $thirdMap ); |
|
622 | + $actual = $firstMap->concat( $thirdMap )->toArray(); |
|
623 | 623 | |
624 | - $this->assertSame($expected, $actual); |
|
624 | + $this->assertSame( $expected, $actual ); |
|
625 | 625 | } |
626 | 626 | |
627 | 627 | public function testReduce() |
628 | 628 | { |
629 | - $data = new Map([1, 2, 3]); |
|
630 | - $this->assertEquals(6, $data->reduce( function( $carry, $element ) { |
|
629 | + $data = new Map( [1, 2, 3] ); |
|
630 | + $this->assertEquals( 6, $data->reduce( function( $carry, $element ) { |
|
631 | 631 | return $carry += $element; |
632 | - } )); |
|
632 | + } ) ); |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | public function testPipe() |
636 | 636 | { |
637 | - $map = new Map([1, 2, 3]); |
|
637 | + $map = new Map( [1, 2, 3] ); |
|
638 | 638 | |
639 | 639 | $this->assertEquals( 3, $map->pipe( function( $map ) { |
640 | 640 | return $map->last(); |
@@ -643,73 +643,73 @@ discard block |
||
643 | 643 | |
644 | 644 | public function testSliceOffset() |
645 | 645 | { |
646 | - $map = new Map([1, 2, 3, 4, 5, 6, 7, 8]); |
|
647 | - $this->assertEquals([4, 5, 6, 7, 8], $map->slice(3)->values()->toArray()); |
|
646 | + $map = new Map( [1, 2, 3, 4, 5, 6, 7, 8] ); |
|
647 | + $this->assertEquals( [4, 5, 6, 7, 8], $map->slice( 3 )->values()->toArray() ); |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | public function testSliceNegativeOffset() |
651 | 651 | { |
652 | - $map = new Map([1, 2, 3, 4, 5, 6, 7, 8]); |
|
653 | - $this->assertEquals([6, 7, 8], $map->slice(-3)->values()->toArray()); |
|
652 | + $map = new Map( [1, 2, 3, 4, 5, 6, 7, 8] ); |
|
653 | + $this->assertEquals( [6, 7, 8], $map->slice(-3)->values()->toArray() ); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | public function testSliceOffsetAndLength() |
657 | 657 | { |
658 | - $map = new Map([1, 2, 3, 4, 5, 6, 7, 8]); |
|
659 | - $this->assertEquals([4, 5, 6], $map->slice(3, 3)->values()->toArray()); |
|
658 | + $map = new Map( [1, 2, 3, 4, 5, 6, 7, 8] ); |
|
659 | + $this->assertEquals( [4, 5, 6], $map->slice( 3, 3 )->values()->toArray() ); |
|
660 | 660 | } |
661 | 661 | |
662 | 662 | public function testSliceOffsetAndNegativeLength() |
663 | 663 | { |
664 | - $map = new Map([1, 2, 3, 4, 5, 6, 7, 8]); |
|
665 | - $this->assertEquals([4, 5, 6, 7], $map->slice(3, -1)->values()->toArray()); |
|
664 | + $map = new Map( [1, 2, 3, 4, 5, 6, 7, 8] ); |
|
665 | + $this->assertEquals( [4, 5, 6, 7], $map->slice( 3, -1 )->values()->toArray() ); |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | public function testSliceNegativeOffsetAndLength() |
669 | 669 | { |
670 | - $map = new Map([1, 2, 3, 4, 5, 6, 7, 8]); |
|
671 | - $this->assertEquals([4, 5, 6], $map->slice(-5, 3)->values()->toArray()); |
|
670 | + $map = new Map( [1, 2, 3, 4, 5, 6, 7, 8] ); |
|
671 | + $this->assertEquals( [4, 5, 6], $map->slice(-5, 3)->values()->toArray() ); |
|
672 | 672 | } |
673 | 673 | |
674 | 674 | public function testSliceNegativeOffsetAndNegativeLength() |
675 | 675 | { |
676 | - $map = new Map([1, 2, 3, 4, 5, 6, 7, 8]); |
|
677 | - $this->assertEquals([3, 4, 5, 6], $map->slice(-6, -2)->values()->toArray()); |
|
676 | + $map = new Map( [1, 2, 3, 4, 5, 6, 7, 8] ); |
|
677 | + $this->assertEquals( [3, 4, 5, 6], $map->slice(-6, -2)->values()->toArray() ); |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | public function testMapFromTraversable() |
681 | 681 | { |
682 | - $map = new Map(new \ArrayObject([1, 2, 3])); |
|
683 | - $this->assertEquals([1, 2, 3], $map->toArray()); |
|
682 | + $map = new Map( new \ArrayObject( [1, 2, 3] ) ); |
|
683 | + $this->assertEquals( [1, 2, 3], $map->toArray() ); |
|
684 | 684 | } |
685 | 685 | |
686 | 686 | public function testMapFromTraversableWithKeys() |
687 | 687 | { |
688 | - $map = new Map(new \ArrayObject(['foo' => 1, 'bar' => 2, 'baz' => 3])); |
|
689 | - $this->assertEquals(['foo' => 1, 'bar' => 2, 'baz' => 3], $map->toArray()); |
|
688 | + $map = new Map( new \ArrayObject( ['foo' => 1, 'bar' => 2, 'baz' => 3] ) ); |
|
689 | + $this->assertEquals( ['foo' => 1, 'bar' => 2, 'baz' => 3], $map->toArray() ); |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | public function testHasReturnsValidResults() |
693 | 693 | { |
694 | - $map = new Map(['foo' => 'one', 'bar' => 'two', 1 => 'three']); |
|
695 | - $this->assertTrue($map->has('foo')); |
|
694 | + $map = new Map( ['foo' => 'one', 'bar' => 'two', 1 => 'three'] ); |
|
695 | + $this->assertTrue( $map->has( 'foo' ) ); |
|
696 | 696 | } |
697 | 697 | |
698 | 698 | public function testSetAddsItemToMap() |
699 | 699 | { |
700 | 700 | $map = new Map; |
701 | - $this->assertSame([], $map->toArray()); |
|
702 | - $map->set('foo', 1); |
|
703 | - $this->assertSame(['foo' => 1], $map->toArray()); |
|
704 | - $map->set('bar', ['nested' => 'two']); |
|
705 | - $this->assertSame(['foo' => 1, 'bar' => ['nested' => 'two']], $map->toArray()); |
|
706 | - $map->set('foo', 3); |
|
707 | - $this->assertSame(['foo' => 3, 'bar' => ['nested' => 'two']], $map->toArray()); |
|
701 | + $this->assertSame( [], $map->toArray() ); |
|
702 | + $map->set( 'foo', 1 ); |
|
703 | + $this->assertSame( ['foo' => 1], $map->toArray() ); |
|
704 | + $map->set( 'bar', ['nested' => 'two'] ); |
|
705 | + $this->assertSame( ['foo' => 1, 'bar' => ['nested' => 'two']], $map->toArray() ); |
|
706 | + $map->set( 'foo', 3 ); |
|
707 | + $this->assertSame( ['foo' => 3, 'bar' => ['nested' => 'two']], $map->toArray() ); |
|
708 | 708 | } |
709 | 709 | |
710 | 710 | public function testGetWithNullReturnsNull() |
711 | 711 | { |
712 | - $map = new Map([1, 2, 3]); |
|
713 | - $this->assertNull($map->get(null)); |
|
712 | + $map = new Map( [1, 2, 3] ); |
|
713 | + $this->assertNull( $map->get( null ) ); |
|
714 | 714 | } |
715 | 715 | } |