Passed
Push — master ( 2165e8...93731f )
by Aimeos
04:55
created

MapTest::testCopy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @author Taylor Otwell, Aimeos.org developers
6
 * @package MW
7
 */
8
9
10
namespace Aimeos\MW;
11
12
13
class MapTest extends \PHPUnit\Framework\TestCase
14
{
15
	public function testClear()
16
	{
17
		$c = new Map(['foo', 'bar']);
18
		$this->assertCount(0, $c->clear());
19
	}
20
21
	public function testCopy()
22
	{
23
		$c = new Map(['foo', 'bar']);
24
		$cp = $c->copy();
25
		$c->clear();
26
		$this->assertCount(2, $cp);
27
	}
28
29
	public function testFirstReturnsFirstItemInMap()
30
	{
31
		$c = new Map(['foo', 'bar']);
32
		$this->assertEquals('foo', $c->first());
33
	}
34
35
	public function testFirstWithCallback()
36
	{
37
		$data = new Map(['foo', 'bar', 'baz']);
38
		$result = $data->first( function( $value ) {
39
			return $value === 'bar';
40
		} );
41
		$this->assertEquals('bar', $result);
42
	}
43
44
	public function testFirstWithCallbackAndDefault()
45
	{
46
		$data = new Map(['foo', 'bar']);
47
		$result = $data->first( function( $value ) {
48
			return $value === 'baz';
49
		}, 'default' );
50
		$this->assertEquals('default', $result);
51
	}
52
53
	public function testFirstWithDefaultAndWithoutCallback()
54
	{
55
		$data = new Map;
56
		$result = $data->first(null, 'default');
57
		$this->assertEquals('default', $result);
58
	}
59
60
	public function testLastReturnsLastItemInMap()
61
	{
62
		$c = new Map(['foo', 'bar']);
63
		$this->assertEquals('bar', $c->last());
64
	}
65
66
	public function testLastWithCallback()
67
	{
68
		$data = new Map([100, 200, 300]);
69
		$result = $data->last( function( $value ) {
70
			return $value < 250;
71
		} );
72
		$this->assertEquals(200, $result);
73
		$result = $data->last( function( $value, $key ) {
74
			return $key < 2;
75
		} );
76
		$this->assertEquals(200, $result);
77
	}
78
79
	public function testLastWithCallbackAndDefault()
80
	{
81
		$data = new Map(['foo', 'bar']);
82
		$result = $data->last( function( $value ) {
83
			return $value === 'baz';
84
		}, 'default' );
85
		$this->assertEquals('default', $result);
86
	}
87
88
	public function testLastWithDefaultAndWithoutCallback()
89
	{
90
		$data = new Map;
91
		$result = $data->last(null, 'default');
92
		$this->assertEquals('default', $result);
93
	}
94
95
	public function testPopReturnsAndRemovesLastItemInMap()
96
	{
97
		$c = new Map(['foo', 'bar']);
98
99
		$this->assertEquals('bar', $c->pop());
100
		$this->assertEquals('foo', $c->first());
101
	}
102
103
	public function testShiftReturnsAndRemovesFirstItemInMap()
104
	{
105
		$c = new Map(['foo', 'bar']);
106
107
		$this->assertEquals('foo', $c->shift());
108
		$this->assertEquals('bar', $c->first());
109
	}
110
111
	public function testEmptyMapIsEmpty()
112
	{
113
		$c = new Map;
114
115
		$this->assertTrue($c->isEmpty());
116
	}
117
118
	public function testMapIsConstructed()
119
	{
120
		$map = new Map;
121
		$this->assertEmpty($map->toArray());
122
	}
123
124
	public function testMapShuffle()
125
	{
126
		$map = new Map(range(0, 100, 10));
127
128
		$firstRandom = $map->copy()->shuffle();
129
		$secondRandom = $map->copy()->shuffle();
130
131
		$this->assertNotEquals($firstRandom, $secondRandom);
132
	}
133
134
	public function testGetArray()
135
	{
136
		$map = new Map;
137
138
		$class = new \ReflectionClass($map);
139
		$method = $class->getMethod('getArray');
140
		$method->setAccessible(true);
141
142
		$items = new \ArrayIterator( ['foo' => 'bar']);
143
		$array = $method->invokeArgs($map, [$items]);
144
		$this->assertSame(['foo' => 'bar'], $array);
145
146
		$items = new Map(['foo' => 'bar']);
147
		$array = $method->invokeArgs($map, [$items]);
148
		$this->assertSame(['foo' => 'bar'], $array);
149
150
		$items = ['foo' => 'bar'];
151
		$array = $method->invokeArgs($map, [$items]);
152
		$this->assertSame(['foo' => 'bar'], $array);
153
	}
154
155
	public function testOffsetAccess()
156
	{
157
		$c = new Map(['name' => 'test']);
158
		$this->assertEquals('test', $c['name']);
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']));
164
		$c[] = 'jason';
165
		$this->assertEquals('jason', $c[0]);
166
	}
167
168
	public function testArrayAccessOffsetExists()
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));
174
	}
175
176
	public function testArrayAccessOffsetGet()
177
	{
178
		$c = new Map(['foo', 'bar']);
179
		$this->assertEquals('foo', $c->offsetGet(0));
180
		$this->assertEquals('bar', $c->offsetGet(1));
181
	}
182
183
	public function testArrayAccessOffsetSet()
184
	{
185
		$c = new Map(['foo', 'foo']);
186
187
		$c->offsetSet(1, 'bar');
188
		$this->assertEquals('bar', $c[1]);
189
190
		$c->offsetSet(null, 'qux');
191
		$this->assertEquals('qux', $c[2]);
192
	}
193
194
	public function testArrayAccessOffsetUnset()
195
	{
196
		$c = new Map(['foo', 'bar']);
197
198
		$c->offsetUnset(1);
199
		$this->assertFalse(isset($c[1]));
200
	}
201
202
	public function testRemoveSingleKey()
203
	{
204
		$c = new Map(['foo', 'bar']);
205
		$c->remove(0);
206
		$this->assertFalse(isset($c['foo']));
207
208
		$c = new Map(['foo' => 'bar', 'baz' => 'qux']);
209
		$c->remove('foo');
210
		$this->assertFalse(isset($c['foo']));
211
	}
212
213
	public function testRemoveArrayOfKeys()
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]));
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']));
226
	}
227
228
	public function testCountable()
229
	{
230
		$c = new Map(['foo', 'bar']);
231
		$this->assertCount(2, $c);
232
	}
233
234
	public function testIterable()
235
	{
236
		$c = new Map(['foo']);
237
		$this->assertInstanceOf(\ArrayIterator::class, $c->getIterator());
238
		$this->assertEquals(['foo'], $c->getIterator()->getArrayCopy());
239
	}
240
241
	public function testFilter()
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 ) {
245
			return $item['id'] == 2;
246
		} )->toArray());
247
248
		$c = new Map(['', 'Hello', '', 'World']);
249
		$this->assertEquals(['Hello', 'World'], $c->filter()->values()->toArray());
250
251
		$c = new Map(['id' => 1, 'first' => 'Hello', 'second' => 'World']);
252
		$this->assertEquals(['first' => 'Hello', 'second' => 'World'], $c->filter( function( $item, $key ) {
253
			return $key != 'id';
254
		} )->toArray());
255
	}
256
257
	public function testValues()
258
	{
259
		$c = new Map([['id' => 1, 'name' => 'Hello'], ['id' => 2, 'name' => 'World']]);
260
		$this->assertEquals([['id' => 2, 'name' => 'World']], $c->filter( function( $item ) {
261
			return $item['id'] == 2;
262
		} )->values()->toArray());
263
	}
264
265
	public function testMergeArray()
266
	{
267
		$c = new Map(['name' => 'Hello']);
268
		$this->assertEquals(['name' => 'Hello', 'id' => 1], $c->merge(['id' => 1])->toArray());
269
	}
270
271
	public function testMergeMap()
272
	{
273
		$c = new Map(['name' => 'Hello']);
274
		$this->assertEquals(['name' => 'World', 'id' => 1], $c->merge(new Map(['name' => 'World', 'id' => 1]))->toArray());
275
	}
276
277
	public function testReplaceArray()
278
	{
279
		$c = new Map(['a', 'b', 'c']);
280
		$this->assertEquals(['a', 'd', 'e'], $c->replace([1 => 'd', 2 => 'e'])->toArray());
281
	}
282
283
	public function testReplaceMap()
284
	{
285
		$c = new Map(['a', 'b', 'c']);
286
		$this->assertEquals(
287
			['a', 'd', 'e'],
288
			$c->replace(new Map([1 => 'd', 2 => 'e']))->toArray()
289
		);
290
	}
291
292
	public function testReplaceRecursiveArray()
293
	{
294
		$c = new Map(['a', 'b', ['c', 'd']]);
295
		$this->assertEquals(['z', 'b', ['c', 'e']], $c->replace(['z', 2 => [1 => 'e']])->toArray());
296
	}
297
298
	public function testReplaceRecursiveMap()
299
	{
300
		$c = new Map(['a', 'b', ['c', 'd']]);
301
		$this->assertEquals(
302
			['z', 'b', ['c', 'e']],
303
			$c->replace(new Map(['z', 2 => [1 => 'e']]))->toArray()
304
		);
305
	}
306
307
	public function testUnionArray()
308
	{
309
		$c = new Map(['name' => 'Hello']);
310
		$this->assertEquals(['name' => 'Hello', 'id' => 1], $c->union(['id' => 1])->toArray());
311
	}
312
313
	public function testUnionMap()
314
	{
315
		$c = new Map(['name' => 'Hello']);
316
		$this->assertEquals(['name' => 'Hello', 'id' => 1], $c->union(new Map(['name' => 'World', 'id' => 1]))->toArray());
317
	}
318
319
	public function testDiffMap()
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());
323
	}
324
325
	public function testDiffUsingWithMap()
326
	{
327
		$c = new Map(['en_GB', 'fr', 'HR']);
328
		// demonstrate that diffKeys wont support case insensitivity
329
		$this->assertEquals(['en_GB', 'fr', 'HR'], $c->diff(new Map(['en_gb', 'hr']))->values()->toArray());
330
	}
331
332
	public function testDiffKeys()
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());
337
	}
338
339
	public function testDiffKeysFunction()
340
	{
341
		$c1 = new Map(['id' => 1, 'first_word' => 'Hello']);
342
		$c2 = new Map(['ID' => 123, 'foo_bar' => 'Hello']);
343
		// demonstrate that diffKeys wont support case insensitivity
344
		$this->assertEquals(['id'=>1, 'first_word'=> 'Hello'], $c1->diffKeys($c2)->toArray());
345
		// allow for case insensitive difference
346
		$this->assertEquals(['first_word' => 'Hello'], $c1->diffKeys($c2, 'strcasecmp')->toArray());
347
	}
348
349
	public function testDiffAssoc()
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());
354
	}
355
356
	public function testDiffAssocFunction()
357
	{
358
		$c1 = new Map(['a' => 'green', 'b' => 'brown', 'c' => 'blue', 'red']);
359
		$c2 = new Map(['A' => 'green', 'yellow', 'red']);
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());
362
		// allow for case insensitive difference
363
		$this->assertEquals(['b' => 'brown', 'c' => 'blue', 'red'], $c1->diffAssoc($c2, 'strcasecmp')->toArray());
364
	}
365
366
	public function testEach()
367
	{
368
		$c = new Map($original = [1, 2, 'foo' => 'bar', 'bam' => 'baz']);
369
370
		$result = [];
371
		$c->each( function( $item, $key ) use ( &$result ) {
372
			$result[$key] = $item;
373
		} );
374
		$this->assertEquals($original, $result);
375
376
		$result = [];
377
		$c->each( function( $item, $key ) use ( &$result ) {
378
			$result[$key] = $item;
379
			if( is_string( $key ) ) {
380
				return false;
381
			}
382
		} );
383
		$this->assertEquals([1, 2, 'foo' => 'bar'], $result);
384
	}
385
386
	public function testIntersectMap()
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());
390
	}
391
392
	public function testIntersectKeys()
393
	{
394
		$c = new Map(['name' => 'Mateus', 'age' => 18]);
395
		$this->assertEquals(['name' => 'Mateus'], $c->intersectKeys(new Map(['name' => 'Mateus', 'surname' => 'Guimaraes']))->toArray());
396
	}
397
398
	public function testUnique()
399
	{
400
		$c = new Map(['Hello', 'World', 'World']);
401
		$this->assertEquals(['Hello', 'World'], $c->unique()->toArray());
402
	}
403
404
	public function testSort()
405
	{
406
		$data = (new Map([5, 3, 1, 2, 4]))->sort();
407
		$this->assertEquals([1, 2, 3, 4, 5], $data->values()->toArray());
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());
411
412
		$data = (new Map(['foo', 'bar-10', 'bar-1']))->sort();
413
		$this->assertEquals(['bar-1', 'bar-10', 'foo'], $data->values()->toArray());
414
	}
415
416
	public function testKsort()
417
	{
418
		$data = new Map(['b' => 'me', 'a' => 'test']);
419
420
		$this->assertSame(['a' => 'test', 'b' => 'me'], $data->ksort()->toArray());
421
	}
422
423
	public function testReverse()
424
	{
425
		$data = new Map(['hello', 'world']);
426
		$reversed = $data->reverse();
427
428
		$this->assertSame([1 => 'world', 0 => 'hello'], $reversed->toArray());
429
430
		$data = new Map(['name' => 'test', 'last' => 'user']);
431
		$reversed = $data->reverse();
432
433
		$this->assertSame(['last' => 'user', 'name' => 'test'], $reversed->toArray());
434
	}
435
436
	public function testHas()
437
	{
438
		$data = new Map(['id' => 1, 'first' => 'Hello', 'second' => 'World']);
439
		$this->assertTrue($data->has('first'));
440
		$this->assertFalse($data->has('third'));
441
	}
442
443
	public function testMethod()
444
	{
445
		Map::method('foo', function() {
446
			return $this->filter( function( $item ) {
0 ignored issues
show
Bug introduced by
The method filter() does not exist on Aimeos\MW\MapTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

446
			return $this->/** @scrutinizer ignore-call */ filter( function( $item ) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
447
				return strpos($item, 'a') === 0;
448
			})
449
				->unique()
450
				->values();
451
		} );
452
453
		$c = new Map(['a', 'a', 'aa', 'aaa', 'bar']);
454
455
		$this->assertSame(['a', 'aa', 'aaa'], $c->foo()->toArray());
0 ignored issues
show
Bug introduced by
The method foo() does not exist on Aimeos\MW\Map. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

455
		$this->assertSame(['a', 'aa', 'aaa'], $c->/** @scrutinizer ignore-call */ foo()->toArray());
Loading history...
456
	}
457
458
	public function testMakeMethodFromMap()
459
	{
460
		$firstMap = Map::from(['foo' => 'bar']);
461
		$secondMap = Map::from($firstMap);
462
		$this->assertEquals(['foo' => 'bar'], $secondMap->toArray());
463
	}
464
465
	public function testMakeMethodFromArray()
466
	{
467
		$map = Map::from(['foo' => 'bar']);
468
		$this->assertEquals(['foo' => 'bar'], $map->toArray());
469
	}
470
471
	public function testConstructMethodFromMap()
472
	{
473
		$firstMap = new Map(['foo' => 'bar']);
474
		$secondMap = new Map($firstMap);
475
		$this->assertEquals(['foo' => 'bar'], $secondMap->toArray());
476
	}
477
478
	public function testConstructMethodFromArray()
479
	{
480
		$map = new Map(['foo' => 'bar']);
481
		$this->assertEquals(['foo' => 'bar'], $map->toArray());
482
	}
483
484
	public function testSplice()
485
	{
486
		$data = new Map(['foo', 'baz']);
487
		$data->splice(1);
488
		$this->assertEquals(['foo'], $data->toArray());
489
490
		$data = new Map(['foo', 'baz']);
491
		$data->splice(1, 0, 'bar');
492
		$this->assertEquals(['foo', 'bar', 'baz'], $data->toArray());
493
494
		$data = new Map(['foo', 'baz']);
495
		$data->splice(1, 1);
496
		$this->assertEquals(['foo'], $data->toArray());
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());
502
	}
503
504
	public function testMap()
505
	{
506
		$data = new Map(['first' => 'test', 'last' => 'user']);
507
		$data = $data->map( function( $item, $key ) {
508
			return $key.'-'.strrev($item);
509
		} );
510
		$this->assertEquals(['first' => 'first-tset', 'last' => 'last-resu'], $data->toArray());
511
	}
512
513
	public function testPullRetrievesItemFromMap()
514
	{
515
		$c = new Map(['foo', 'bar']);
516
517
		$this->assertEquals('foo', $c->pull(0));
518
	}
519
520
	public function testPullRemovesItemFromMap()
521
	{
522
		$c = new Map(['foo', 'bar']);
523
		$c->pull(0);
524
		$this->assertEquals([1 => 'bar'], $c->toArray());
525
	}
526
527
	public function testPullReturnsDefault()
528
	{
529
		$c = new Map([]);
530
		$value = $c->pull(0, 'foo');
531
		$this->assertEquals('foo', $value);
532
	}
533
534
	public function testSearch()
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(''));
544
	}
545
546
	public function testSearchReturnsNullWhenItemIsNotFound()
547
	{
548
		$c = new Map([1, 2, 3, 4, 5, 'foo' => 'bar']);
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 ) {
556
			return $value == 'nope';
557
		} ));
558
	}
559
560
	public function testKeys()
561
	{
562
		$c = new Map(['name' => 'test', 'last' => 'user']);
563
		$this->assertEquals(['name', 'last'], $c->keys()->toArray());
564
	}
565
566
	public function testUnshift()
567
	{
568
		$c = new Map(['one', 'two', 'three', 'four']);
569
		$this->assertEquals(['zero', 'one', 'two', 'three', 'four'], $c->unshift('zero')->toArray());
570
571
		$c = new Map(['one' => 1, 'two' => 2]);
572
		$this->assertEquals(['zero' => 0, 'one' => 1, 'two' => 2], $c->unshift(0, 'zero')->toArray());
573
	}
574
575
	public function testConcatWithArray()
576
	{
577
		$expected = [
578
			0 => 4,
579
			1 => 5,
580
			2 => 6,
581
			3 => 'a',
582
			4 => 'b',
583
			5 => 'c',
584
			6 => 'Jonny',
585
			7 => 'from',
586
			8 => 'Laroe',
587
			9 => 'Jonny',
588
			10 => 'from',
589
			11 => 'Laroe',
590
		];
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();
596
597
		$this->assertSame($expected, $actual);
598
	}
599
600
	public function testConcatWithMap()
601
	{
602
		$expected = [
603
			0 => 4,
604
			1 => 5,
605
			2 => 6,
606
			3 => 'a',
607
			4 => 'b',
608
			5 => 'c',
609
			6 => 'Jonny',
610
			7 => 'from',
611
			8 => 'Laroe',
612
			9 => 'Jonny',
613
			10 => 'from',
614
			11 => 'Laroe',
615
		];
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();
623
624
		$this->assertSame($expected, $actual);
625
	}
626
627
	public function testReduce()
628
	{
629
		$data = new Map([1, 2, 3]);
630
		$this->assertEquals(6, $data->reduce( function( $carry, $element ) {
631
			return $carry += $element;
632
		} ));
633
	}
634
635
	public function testPipe()
636
	{
637
		$map = new Map([1, 2, 3]);
638
639
		$this->assertEquals( 3, $map->pipe( function( $map ) {
640
			return $map->last();
641
		} ) );
642
	}
643
644
	public function testSliceOffset()
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());
648
	}
649
650
	public function testSliceNegativeOffset()
651
	{
652
		$map = new Map([1, 2, 3, 4, 5, 6, 7, 8]);
653
		$this->assertEquals([6, 7, 8], $map->slice(-3)->values()->toArray());
654
	}
655
656
	public function testSliceOffsetAndLength()
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());
660
	}
661
662
	public function testSliceOffsetAndNegativeLength()
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());
666
	}
667
668
	public function testSliceNegativeOffsetAndLength()
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());
672
	}
673
674
	public function testSliceNegativeOffsetAndNegativeLength()
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());
678
	}
679
680
	public function testMapFromTraversable()
681
	{
682
		$map = new Map(new \ArrayObject([1, 2, 3]));
683
		$this->assertEquals([1, 2, 3], $map->toArray());
684
	}
685
686
	public function testMapFromTraversableWithKeys()
687
	{
688
		$map = new Map(new \ArrayObject(['foo' => 1, 'bar' => 2, 'baz' => 3]));
689
		$this->assertEquals(['foo' => 1, 'bar' => 2, 'baz' => 3], $map->toArray());
690
	}
691
692
	public function testHasReturnsValidResults()
693
	{
694
		$map = new Map(['foo' => 'one', 'bar' => 'two', 1 => 'three']);
695
		$this->assertTrue($map->has('foo'));
696
	}
697
698
	public function testSetAddsItemToMap()
699
	{
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());
708
	}
709
710
	public function testGetWithNullReturnsNull()
711
	{
712
		$map = new Map([1, 2, 3]);
713
		$this->assertNull($map->get(null));
714
	}
715
}
716