GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#50)
by
unknown
08:42
created

CollectionSpec::it_can_replace_by_key()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace spec\DusanKasan\Knapsack;
4
5
use ArrayIterator;
6
use DOMXPath;
7
use DusanKasan\Knapsack\Collection;
8
use DusanKasan\Knapsack\Exceptions\InvalidArgument;
9
use DusanKasan\Knapsack\Exceptions\InvalidReturnValue;
10
use DusanKasan\Knapsack\Exceptions\ItemNotFound;
11
use DusanKasan\Knapsack\Exceptions\NoMoreItems;
12
use DusanKasan\Knapsack\Tests\Helpers\PlusOneAdder;
13
use IteratorAggregate;
14
use PhpSpec\ObjectBehavior;
15
use Serializable;
16
use Traversable;
17
18
/**
19
 * @mixin Collection
20
 */
21
class CollectionSpec extends ObjectBehavior
22
{
23
    function it_is_initializable()
24
    {
25
        $this->beConstructedWith([1, 2, 3]);
26
        $this->shouldHaveType(Collection::class);
27
        $this->shouldHaveType(Traversable::class);
28
        $this->shouldHaveType(Serializable::class);
29
    }
30
31
    function it_can_be_instantiated_from_iterator()
32
    {
33
        $iterator = new ArrayIterator([1, 2]);
34
        $this->beConstructedWith($iterator);
35
        $this->toArray()->shouldReturn([1, 2]);
36
    }
37
38
    function it_can_be_instantiated_from_iterator_aggregate(IteratorAggregate $iteratorAggregate)
39
    {
40
        $iterator = new ArrayIterator([1, 2]);
41
        $iteratorAggregate->getIterator()->willReturn($iterator);
42
        $this->beConstructedWith($iteratorAggregate);
43
        $this->toArray()->shouldReturn([1, 2]);
44
    }
45
46
    function it_can_be_instantiated_from_array()
47
    {
48
        $this->beConstructedWith([1, 2, 3]);
49
        $this->toArray()->shouldReturn([1, 2, 3]);
50
    }
51
52
    function it_will_throw_when_passed_something_other_than_array_or_traversable()
53
    {
54
        $this->beConstructedWith(1);
55
        $this->shouldThrow(InvalidArgument::class)->duringInstantiation();
56
    }
57
58
    function it_can_be_instantiated_from_callable_returning_an_array()
59
    {
60
        $this->beConstructedWith(function () { return [1, 2, 3]; });
61
        $this->toArray()->shouldReturn([1, 2, 3]);
62
    }
63
64
    function it_can_be_instantiated_from_callable_returning_an_iterator()
65
    {
66
        $this->beConstructedWith(function () { return new ArrayIterator([1, 2, 3]); });
67
        $this->toArray()->shouldReturn([1, 2, 3]);
68
    }
69
70
    function it_can_be_instantiated_from_callable_returning_a_generator()
71
    {
72
        $this->beConstructedWith(function () {
73
            foreach ([1, 2, 3] as $value) {
74
                yield $value;
75
            }
76
        });
77
        $this->toArray()->shouldReturn([1, 2, 3]);
78
    }
79
80
    function it_will_throw_when_passed_callable_will_return_something_other_than_array_or_traversable()
81
    {
82
        $this->beConstructedWith(function () { return 1; });
83
        $this->shouldThrow(InvalidReturnValue::class)->duringInstantiation();
84
    }
85
86
    function it_can_be_created_statically()
87
    {
88
        $this->beConstructedThrough('from', [[1, 2]]);
89
        $this->toArray()->shouldReturn([1, 2]);
90
    }
91
92
    function it_can_be_created_to_iterate_over_function_infinitely()
93
    {
94
        $this->beConstructedThrough('iterate', [1, function ($i) {return $i + 1;}]);
95
        $this->take(2)->toArray()->shouldReturn([1, 2]);
96
    }
97
98
    function it_can_be_created_to_iterate_over_function_non_infinitely()
99
    {
100
        $this->beConstructedThrough(
101
            'iterate',
102
            [
103
                1,
104
                function ($i) {
105
                    if ($i > 3) {
106
                        throw new NoMoreItems;
107
                    }
108
109
                    return $i + 1;
110
                },
111
            ]
112
        );
113
        $this->toArray()->shouldReturn([1, 2, 3, 4]);
114
    }
115
116
    function it_can_be_created_to_repeat_a_value_infinite_times()
117
    {
118
        $this->beConstructedThrough('repeat', [1]);
119
        $this->take(2)->toArray()->shouldReturn([1, 1]);
120
    }
121
122
    function it_can_convert_to_array()
123
    {
124
        $iterator = new \ArrayIterator([
125
            'foo',
126
        ]);
127
128
        $this->beConstructedWith(function () use ($iterator) {
129
            yield 'no key';
130
            yield 'with key' => 'this value is overwritten by the same key';
131
            yield 'nested' => [
132
                'y' => 'z',
133
            ];
134
            yield 'iterator is not converted' => $iterator;
135
            yield 'with key' => 'x';
136
        });
137
138
        $this
139
            ->toArray()
140
            ->shouldReturn([
141
                'no key',
142
                'with key' => 'x',
143
                'nested' => [
144
                    'y' => 'z',
145
                ],
146
                'iterator is not converted' => $iterator,
147
            ]);
148
    }
149
150
    function it_can_filter()
151
    {
152
        $this->beConstructedWith([1, 3, 3, 2,]);
153
154
        $this
155
            ->filter(function ($item) {
156
                return $item > 2;
157
            })
158
            ->toArray()
159
            ->shouldReturn([1 => 3, 2 => 3]);
160
161
        $this
162
            ->filter(function ($item, $key) {
163
                return $key > 2 && $item < 3;
164
            })
165
            ->toArray()
166
            ->shouldReturn([3 => 2]);
167
    }
168
169
    function it_can_filter_falsy_values()
170
    {
171
        $this->beConstructedWith([false, null, '', 0, 0.0, []]);
172
173
        $this->filter()->isEmpty()->shouldReturn(true);
174
    }
175
176
    function it_can_distinct()
177
    {
178
        $this->beConstructedWith([1, 3, 3, 2,]);
179
180
        $this
181
            ->distinct()
182
            ->toArray()
183
            ->shouldReturn([1, 3, 3 => 2]);
184
    }
185
186
    function it_can_concat()
187
    {
188
        $this->beConstructedWith([1, 3, 3, 2,]);
189
190
        $collection = $this->concat([4, 5]);
191
        $collection->toArray()->shouldReturn([4, 5, 3, 2]);
192
        $collection->size()->shouldReturn(6);
193
    }
194
195 View Code Duplication
    function it_can_map()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
196
    {
197
        $this->beConstructedWith([1, 3, 3, 2,]);
198
199
        $this
200
            ->map(function ($item) {
201
                return $item + 1;
202
            })
203
            ->toArray()
204
            ->shouldReturn([2, 4, 4, 3]);
205
    }
206
207
208
	function it_can_implode()
209
	{
210
		$this->beConstructedWith(['a', 'b', 'c',]);
211
212
		$this
213
			->implode(', ')
214
			->shouldReturn('a, b, c');
215
	}
216
217
    function it_can_reduce()
218
    {
219
        $this->beConstructedWith([1, 3, 3, 2,]);
220
221
        $this
222
            ->reduce(
223
                function ($temp, $item) {
224
                    $temp[] = $item;
225
226
                    return $temp;
227
                },
228
                ['a' => [1]],
229
                true
230
            )
231
            ->values()
232
            ->toArray()
233
            ->shouldReturn([[1], 1, 3, 3, 2]);
234
235
        $this
236
            ->reduce(
237
                function ($temp, $item) {
238
                    return $temp + $item;
239
                },
240
                0
241
            )
242
            ->shouldReturn(9);
243
244
        $this
245
            ->reduce(
246
                function ($temp, $item, $key) {
247
                    return $temp + $key + $item;
248
                },
249
                0
250
            )
251
            ->shouldReturn(15);
252
253
        $this
254
            ->reduce(
255
                function (Collection $temp, $item) {
256
                    return $temp->append($item);
257
                },
258
                new Collection([])
259
            )
260
            ->toArray()
261
            ->shouldReturn([1, 3, 3, 2]);
262
    }
263
264
    function it_can_flatten()
265
    {
266
        $this->beConstructedWith([1, [2, [3]]]);
267
        $this->flatten()->values()->toArray()->shouldReturn([1, 2, 3]);
268
        $this->flatten(1)->values()->toArray()->shouldReturn([1, 2, [3]]);
269
    }
270
271
    function it_can_sort()
272
    {
273
        $this->beConstructedWith([3, 1, 2]);
274
275
        $this
276
            ->sort(function ($a, $b) {
277
                return $a > $b;
278
            })
279
            ->toArray()
280
            ->shouldReturn([1 => 1, 2 => 2, 0 => 3]);
281
282
        $this
283
            ->sort(function ($v1, $v2, $k1, $k2) {
284
                return $k1 < $k2 || $v1 == $v2;
285
            })
286
            ->toArray()
287
            ->shouldReturn([2 => 2, 1 => 1, 0 => 3]);
288
    }
289
290
    function it_can_slice()
291
    {
292
        $this->beConstructedWith([1, 2, 3, 4, 5]);
293
294
        $this
295
            ->slice(2, 4)
296
            ->toArray()
297
            ->shouldReturn([2 => 3, 3 => 4]);
298
299
        $this
300
            ->slice(4)
301
            ->toArray()
302
            ->shouldReturn([4 => 5]);
303
    }
304
305
    function it_can_group_by()
306
    {
307
        $this->beConstructedWith([1, 2, 3, 4, 5]);
308
309
        $collection = $this->groupBy(function ($i) {
310
            return $i % 2;
311
        });
312
313
        $collection->get(0)->toArray()->shouldReturn([2, 4]);
314
        $collection->get(1)->toArray()->shouldReturn([1, 3, 5]);
315
316
        $collection = $this->groupBy(function ($k, $i) {
317
            return ($k + $i) % 3;
318
        });
319
        $collection->get(0)->toArray()->shouldReturn([2, 5]);
320
        $collection->get(1)->toArray()->shouldReturn([1, 4]);
321
        $collection->get(2)->toArray()->shouldReturn([3]);
322
    }
323
324
    function it_can_group_by_key()
325
    {
326
        $this->beConstructedWith([
327
            'some' => 'thing',
328
            ['letter' => 'A', 'type' => 'caps'],
329
            ['letter' => 'a', 'type' => 'small'],
330
            ['letter' => 'B', 'type' => 'caps'],
331
            ['letter' => 'Z'],
332
        ]);
333
334
        $collection = $this->groupByKey('type');
335
        $collection->get('small')->toArray()->shouldReturn([
336
            ['letter' => 'a', 'type' => 'small'],
337
        ]);
338
        $collection->get('caps')->toArray()->shouldReturn([
339
            ['letter' => 'A', 'type' => 'caps'],
340
            ['letter' => 'B', 'type' => 'caps'],
341
        ]);
342
343
        $collection = $this->groupByKey('types');
344
        $collection->shouldThrow(new ItemNotFound)->during('get', ['caps']);
345
    }
346
347
    function it_can_execute_callback_for_each_item(DOMXPath $a)
348
    {
349
        $a->query('asd')->shouldBeCalled();
350
        $this->beConstructedWith([$a]);
351
352
        $this
353
            ->each(function (DOMXPath $i) {
354
                $i->query('asd');
355
            })
356
            ->toArray()
357
            ->shouldReturn([$a]);
358
    }
359
360
    function it_can_get_size()
361
    {
362
        $this->beConstructedWith([1, 3, 3, 2,]);
363
        $this->size()->shouldReturn(4);
364
    }
365
366
    function it_can_get_item_by_key()
367
    {
368
        $this->beConstructedWith([1, [2], 3]);
369
        $this->get(0)->shouldReturn(1);
370
        $this->get(1, true)->first()->shouldReturn(2);
371
        $this->get(1)->shouldReturn([2]);
372
        $this->shouldThrow(new ItemNotFound)->during('get', [5]);
373
    }
374
375
    function it_can_get_item_by_key_or_return_default()
376
    {
377
        $this->beConstructedWith([1, [2], 3]);
378
        $this->getOrDefault(0)->shouldReturn(1);
379
        $this->getOrDefault(1, null, true)->first()->shouldReturn(2);
380
        $this->getOrDefault(1, null)->shouldReturn([2]);
381
        $this->getOrDefault(5)->shouldReturn(null);
382
        $this->getOrDefault(5, 'not found')->shouldReturn('not found');
383
    }
384
385
    function it_can_find()
386
    {
387
        $this->beConstructedWith([1, 3, 3, 2, [5]]);
388
389
        $this
390
            ->find(function ($v) {
391
                return $v < 3;
392
            })
393
            ->shouldReturn(1);
394
395
        $this
396
            ->find(function ($v, $k) {
397
                return $v < 3 && $k > 1;
398
            })
399
            ->shouldReturn(2);
400
401
        $this
402
            ->find(function ($v) {
403
                return $v < 0;
404
            })
405
            ->shouldReturn(null);
406
407
        $this
408
            ->find(
409
                function ($v) {
410
                    return $v < 0;
411
                },
412
                'not found'
413
            )
414
            ->shouldReturn('not found');
415
416
        $this->find('\DusanKasan\Knapsack\isCollection', null, true)->first()->shouldReturn(5);
417
        $this->find('\DusanKasan\Knapsack\isCollection')->shouldReturn([5]);
418
    }
419
420
    function it_can_count_by()
421
    {
422
        $this->beConstructedWith([1, 3, 3, 2,]);
423
424
        $this
425
            ->countBy(function ($v) {
426
                return $v % 2 == 0 ? 'even' : 'odd';
427
            })
428
            ->toArray()
429
            ->shouldReturn(['odd' => 3, 'even' => 1]);
430
431
        $this
432
            ->countBy(function ($k, $v) {
433
                return ($k + $v) % 2 == 0 ? 'even' : 'odd';
434
            })
435
            ->toArray()
436
            ->shouldReturn(['odd' => 3, 'even' => 1]);
437
    }
438
439
    function it_can_index_by()
440
    {
441
        $this->beConstructedWith([1, 3, 3, 2,]);
442
443
        $this
444
            ->indexBy(function ($v) {
445
                return $v;
446
            })
447
            ->toArray()
448
            ->shouldReturn([1 => 1, 3 => 3, 2 => 2]);
449
450
        $this
451
            ->indexBy(function ($v, $k) {
452
                return $k . $v;
453
            })
454
            ->toArray()
455
            ->shouldReturn(['01' => 1, '13' => 3, '23' => 3, '32' => 2]);
456
    }
457
458
    function it_can_check_if_every_item_passes_predicament_test()
459
    {
460
        $this->beConstructedWith([1, 3, 3, 2,]);
461
462
        $this
463
            ->every(function ($v) {
464
                return $v > 0;
465
            })
466
            ->shouldReturn(true);
467
468
        $this
469
            ->every(function ($v) {
470
                return $v > 1;
471
            })
472
            ->shouldReturn(false);
473
474
        $this
475
            ->every(function ($v, $k) {
476
                return $v > 0 && $k >= 0;
477
            })
478
            ->shouldReturn(true);
479
480
        $this
481
            ->every(function ($v, $k) {
482
                return $v > 0 && $k > 0;
483
            })
484
            ->shouldReturn(false);
485
    }
486
487
    function it_can_check_if_some_items_pass_predicament_test()
488
    {
489
        $this->beConstructedWith([1, 3, 3, 2,]);
490
491
        $this
492
            ->some(function ($v) {
493
                return $v < -1;
494
            })
495
            ->shouldReturn(false);
496
497
        $this
498
            ->some(function ($v, $k) {
499
                return $v > 0 && $k < -1;
500
            })
501
            ->shouldReturn(false);
502
503
        $this
504
            ->some(function ($v) {
505
                return $v < 2;
506
            })
507
            ->shouldReturn(true);
508
509
        $this
510
            ->some(function ($v, $k) {
511
                return $v > 0 && $k > 0;
512
            })
513
            ->shouldReturn(true);
514
    }
515
516 View Code Duplication
    function it_can_check_if_it_contains_a_value()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
517
    {
518
        $this->beConstructedWith([1, 3, 3, 2,]);
519
520
        $this
521
            ->contains(3)
522
            ->shouldReturn(true);
523
524
        $this
525
            ->contains(true)
526
            ->shouldReturn(false);
527
    }
528
529
    function it_can_reverse()
530
    {
531
        $this->beConstructedWith([1, 3, 3, 2,]);
532
533
        $this
534
            ->reverse()
535
            ->toArray()
536
            ->shouldReturn([
537
                3 => 2,
538
                2 => 3,
539
                1 => 3,
540
                0 => 1,
541
            ])
542
        ;
543
    }
544
545
    function it_can_reduce_from_right()
546
    {
547
        $this->beConstructedWith([1, 3, 3, 2,]);
548
549
        $this
550
            ->reduceRight(
551
                function ($temp, $e) {
552
                    return $temp . $e;
553
                },
554
                0
555
            )
556
            ->shouldReturn('02331');
557
558
        $this
559
            ->reduceRight(
560
                function ($temp, $key, $item) {
561
                    return $temp + $key + $item;
562
                },
563
                0
564
            )
565
            ->shouldReturn(15);
566
567
        $this
568
            ->reduceRight(
569
                function (Collection $temp, $item) {
570
                    return $temp->append($item);
571
                },
572
                new Collection([])
573
            )
574
            ->toArray()
575
            ->shouldReturn([2, 3, 3, 1]);
576
    }
577
578
    function it_can_return_only_first_x_elements()
579
    {
580
        $this->beConstructedWith([1, 3, 3, 2,]);
581
582
        $this->take(2)
583
            ->toArray()
584
            ->shouldReturn([1, 3]);
585
    }
586
587
    function it_can_skip_first_x_elements()
588
    {
589
        $this->beConstructedWith([1, 3, 3, 2,]);
590
591
        $this->drop(2)
592
            ->toArray()
593
            ->shouldReturn([2 => 3, 3 => 2]);
594
    }
595
596
    function it_can_return_values()
597
    {
598
        $this->beConstructedWith(['a' => 1, 'b' => 2]);
599
        $this->values()->toArray()->shouldReturn([1, 2]);
600
    }
601
602
    function it_can_reject_elements_from_collection()
603
    {
604
        $this->beConstructedWith([1, 3, 3, 2,]);
605
606
        $this
607
            ->reject(function ($v) {
608
                return $v == 3;
609
            })
610
            ->toArray()
611
            ->shouldReturn([1, 3 => 2]);
612
613
        $this
614
            ->reject(function ($v, $k) {
615
                return $k == 2 && $v == 3;
616
            })
617
            ->toArray()
618
            ->shouldReturn([1, 3, 3 => 2]);
619
    }
620
621
    function it_can_get_keys()
622
    {
623
        $this->beConstructedWith([1, 3, 3, 2,]);
624
625
        $this
626
            ->keys()
627
            ->toArray()
628
            ->shouldReturn([0, 1, 2, 3]);
629
    }
630
631 View Code Duplication
    function it_can_interpose()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
632
    {
633
        $this->beConstructedWith([1, 3, 3, 2,]);
634
635
        $this
636
            ->interpose('a')
637
            ->values()
638
            ->toArray()
639
            ->shouldReturn([1, 'a', 3, 'a', 3, 'a', 2]);
640
    }
641
642
    function it_can_drop_elements_from_end_of_the_collection()
643
    {
644
        $this->beConstructedWith([1, 3, 3, 2,]);
645
646
        $this
647
            ->dropLast()
648
            ->toArray()
649
            ->shouldReturn([1, 3, 3]);
650
651
        $this
652
            ->dropLast(2)
653
            ->toArray()
654
            ->shouldReturn([1, 3]);
655
    }
656
657
    function it_can_interleave_elements()
658
    {
659
        $this->beConstructedWith([1, 3, 3, 2,]);
660
661
        $this
662
            ->interleave(['a', 'b', 'c', 'd', 'e'])
663
            ->values()
664
            ->toArray()
665
            ->shouldReturn([1, 'a', 3, 'b', 3, 'c', 2, 'd', 'e']);
666
    }
667
668 View Code Duplication
    function it_can_repeat_items_of_collection_infinitely()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
669
    {
670
        $this->beConstructedWith([1, 3, 3, 2,]);
671
672
        $this
673
            ->cycle()
674
            ->take(8)
675
            ->values()
676
            ->toArray()
677
            ->shouldReturn([1, 3, 3, 2, 1, 3, 3, 2]);
678
    }
679
680 View Code Duplication
    function it_can_prepend_item()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
681
    {
682
        $this->beConstructedWith([1, 3, 3, 2,]);
683
684
        $this
685
            ->prepend(1)
686
            ->values()
687
            ->toArray()
688
            ->shouldReturn([1, 1, 3, 3, 2]);
689
    }
690
691
    function it_can_prepend_item_with_key()
692
    {
693
        $this->beConstructedWith([1, 3, 3, 2,]);
694
695
        $this
696
            ->prepend(1, 'a')
697
            ->toArray()
698
            ->shouldReturn(['a' => 1, 0 => 1, 1 => 3, 2 => 3, 3 => 2]);
699
    }
700
701 View Code Duplication
    function it_can_append_item()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
702
    {
703
        $this->beConstructedWith([1, 3, 3, 2,]);
704
705
        $this
706
            ->append(1)
707
            ->values()
708
            ->toArray()
709
            ->shouldReturn([1, 3, 3, 2, 1]);
710
    }
711
712
    function it_can_append_item_with_key()
713
    {
714
        $this->beConstructedWith([1, 3, 3, 2,]);
715
716
        $this
717
            ->append(1, 'a')
718
            ->toArray()
719
            ->shouldReturn([1, 3, 3, 2, 'a' => 1]);
720
    }
721
722
    function it_can_drop_items_while_predicament_is_true()
723
    {
724
        $this->beConstructedWith([1, 3, 3, 2,]);
725
726
        $this
727
            ->dropWhile(function ($v) {
728
                return $v < 3;
729
            })
730
            ->toArray()
731
            ->shouldReturn([1 => 3, 2 => 3, 3 => 2]);
732
733
        $this
734
            ->dropWhile(function ($v, $k) {
735
                return $k < 2 && $v < 3;
736
            })
737
            ->toArray()
738
            ->shouldReturn([1 => 3, 2 => 3, 3 => 2]);
739
    }
740
741
    function it_can_map_and_then_concatenate_a_collection()
742
    {
743
        $this->beConstructedWith([1, 3, 3, 2,]);
744
745
        $this
746
            ->mapcat(function ($v) {
747
                return [[$v]];
748
            })
749
            ->values()
750
            ->toArray()
751
            ->shouldReturn([[1], [3], [3], [2]]);
752
753
        $this
754
            ->mapcat(function ($v, $k) {
755
                return [[$k + $v]];
756
            })
757
            ->values()
758
            ->toArray()
759
            ->shouldReturn([[1], [4], [5], [5]]);
760
    }
761
762
    function it_can_take_items_while_predicament_is_true()
763
    {
764
        $this->beConstructedWith([1, 3, 3, 2,]);
765
766
        $this
767
            ->takeWhile(function ($v) {
768
                return $v < 3;
769
            })
770
            ->toArray()
771
            ->shouldReturn([1]);
772
773
        $this
774
            ->takeWhile(function ($v, $k) {
775
                return $k < 2 && $v < 3;
776
            })
777
            ->toArray()
778
            ->shouldReturn([1]);
779
    }
780
781
    function it_can_split_the_collection_at_nth_item()
782
    {
783
        $this->beConstructedWith([1, 3, 3, 2,]);
784
785
        $this->splitAt(2)->size()->shouldBe(2);
786
        $this->splitAt(2)->first()->toArray()->shouldBeLike([1, 3]);
787
        $this->splitAt(2)->second()->toArray()->shouldBeLike([2 => 3, 3 => 2]);
788
    }
789
790
    function it_can_split_the_collection_with_predicament()
791
    {
792
        $this->beConstructedWith([1, 3, 3, 2,]);
793
794
        $s1 = $this->splitWith(function ($v) {
795
            return $v < 3;
796
        });
797
798
        $s1->size()->shouldBe(2);
799
        $s1->first()->toArray()->shouldBe([1]);
800
        $s1->second()->toArray()->shouldBe([1 => 3, 2 => 3, 3 => 2]);
801
802
        $s2 = $this->splitWith(function ($v, $k) {
803
            return $v < 2 && $k < 3;
804
        });
805
806
        $s2->size()->shouldBe(2);
807
        $s2->first()->toArray()->shouldBe([1]);
808
        $s2->second()->toArray()->shouldBe([1 => 3, 2 => 3, 3 => 2]);
809
    }
810
811 View Code Duplication
    function it_can_replace_items_by_items_from_another_collection()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
812
    {
813
        $this->beConstructedWith([1, 3, 3, 2,]);
814
815
        $this
816
            ->replace([3 => 'a'])
817
            ->toArray()
818
            ->shouldReturn([1, 'a', 'a', 2]);
819
    }
820
821 View Code Duplication
    function it_can_get_reduction_steps()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
822
    {
823
        $this->beConstructedWith([1, 3, 3, 2,]);
824
825
        $this
826
            ->reductions(
827
                function ($tmp, $i) {
828
                    return $tmp + $i;
829
                },
830
                0
831
            )
832
            ->toArray()
833
            ->shouldReturn([0, 1, 4, 7, 9]);
834
    }
835
836
    function it_can_return_every_nth_item()
837
    {
838
        $this->beConstructedWith([1, 3, 3, 2,]);
839
840
        $this->takeNth(2)
841
            ->toArray()
842
            ->shouldReturn([1, 2 => 3]);
843
    }
844
845
    function it_can_shuffle_itself()
846
    {
847
        $this->beConstructedWith([1, 3, 3, 2,]);
848
849
        $this
850
            ->shuffle()
851
            ->reduce(
852
                function ($tmp, $i) {
853
                    return $tmp + $i;
854
                },
855
                0
856
            )
857
            ->shouldReturn(9);
858
    }
859
860
    function it_can_partition()
861
    {
862
        $this->beConstructedWith([1, 3, 3, 2,]);
863
864
        $s1 = $this->partition(3, 2, [0, 1]);
865
        $s1->size()->shouldBe(2);
866
        $s1->first()->toArray()->shouldBe([1, 3, 3]);
867
        $s1->second()->toArray()->shouldBe([2 => 3, 3 => 2, 0 => 0]);
868
869
        $s2 = $this->partition(3, 2);
870
        $s2->size()->shouldBe(2);
871
        $s2->first()->toArray()->shouldBe([1, 3, 3]);
872
        $s2->second()->toArray()->shouldBe([2 => 3, 3 => 2]);
873
874
        $s3 = $this->partition(3);
875
        $s3->size()->shouldBe(2);
876
        $s3->first()->toArray()->shouldBe([1, 3, 3]);
877
        $s3->second()->toArray()->shouldBe([3 => 2]);
878
879
        $s4 = $this->partition(1, 3);
880
        $s4->size()->shouldBe(2);
881
        $s4->first()->toArray()->shouldBe([1,]);
882
        $s4->second()->toArray()->shouldBe([3 => 2]);
883
    }
884
885
    function it_can_partition_by()
886
    {
887
        $this->beConstructedWith([1, 3, 3, 2]);
888
889
        $s1 = $this->partitionBy(function ($v) {
890
            return $v % 3 == 0;
891
        });
892
        $s1->size()->shouldBe(3);
893
        $s1->first()->toArray()->shouldBe([1]);
894
        $s1->second()->toArray()->shouldBe([1 => 3, 2 => 3]);
895
        $s1->values()->get(2)->toArray()->shouldBe([3 => 2]);
896
897
        $s2 = $this->partitionBy(function ($v, $k) {
898
            return $k - $v;
899
        });
900
        $s2->size()->shouldBe(4);
901
        $s2->first()->toArray()->shouldBe([1]);
902
        $s2->values()->get(1)->toArray()->shouldBe([1 => 3]);
903
        $s2->values()->get(2)->toArray()->shouldBe([2 => 3]);
904
        $s2->values()->get(3)->toArray()->shouldBe([3 => 2]);
905
    }
906
907
    function it_can_get_nth_value()
908
    {
909
        $this->beConstructedWith([1, 3, 3, 2,]);
910
911
        $this->first(0)->shouldReturn(1);
912
        $this->values()->get(3)->shouldReturn(2);
913
    }
914
915
    function it_can_create_infinite_collection_of_repeated_values()
916
    {
917
        $this->beConstructedThrough('repeat', [1]);
918
        $this->take(3)->toArray()->shouldReturn([1, 1, 1]);
919
    }
920
921
    function it_can_create_finite_collection_of_repeated_values()
922
    {
923
        $this->beConstructedThrough('repeat', [1, 1]);
924
        $this->toArray()->shouldReturn([1]);
925
    }
926
927
    function it_can_create_range_from_value_to_infinity()
928
    {
929
        $this->beConstructedThrough('range', [5]);
930
        $this->take(2)->toArray()->shouldReturn([5, 6]);
931
    }
932
933
    function it_can_create_range_from_value_to_another_value()
934
    {
935
        $this->beConstructedThrough('range', [5, 6]);
936
        $this->take(4)->toArray()->shouldReturn([5, 6]);
937
    }
938
939
    function it_can_check_if_it_is_not_empty()
940
    {
941
        $this->beConstructedWith([1, 3, 3, 2,]);
942
943
        $this->isEmpty()->shouldReturn(false);
944
        $this->isNotEmpty()->shouldReturn(true);
945
    }
946
947
    function it_can_check_if_it_is_empty()
948
    {
949
        $this->beConstructedWith([]);
950
951
        $this->isEmpty()->shouldReturn(true);
952
        $this->isNotEmpty()->shouldReturn(false);
953
    }
954
955
    function it_can_check_frequency_of_distinct_items()
956
    {
957
        $this->beConstructedWith([1, 3, 3, 2,]);
958
959
        $this
960
            ->frequencies()
961
            ->toArray()
962
            ->shouldReturn([1 => 1, 3 => 2, 2 => 1]);
963
    }
964
965 View Code Duplication
    function it_can_get_first_item()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
966
    {
967
        $this->beConstructedWith([1, [2], 3]);
968
        $this->first()->shouldReturn(1);
969
        $this->drop(1)->first()->shouldReturn([2]);
970
        $this->drop(1)->first(true)->toArray()->shouldReturn([2]);
971
    }
972
973
    function it_will_throw_when_trying_to_get_first_item_of_empty_collection()
974
    {
975
        $this->beConstructedWith([]);
976
        $this->shouldThrow(ItemNotFound::class)->during('first');
977
    }
978
979 View Code Duplication
    function it_can_get_last_item()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
980
    {
981
        $this->beConstructedWith([1, [2], 3]);
982
        $this->last()->shouldReturn(3);
983
        $this->take(2)->last()->shouldReturn([2]);
984
        $this->take(2)->last(true)->toArray()->shouldReturn([2]);
985
    }
986
987
    function it_will_throw_when_trying_to_get_last_item_of_empty_collection()
988
    {
989
        $this->beConstructedWith([]);
990
        $this->shouldThrow(ItemNotFound::class)->during('last');
991
    }
992
993
    function it_can_realize_the_collection(PlusOneAdder $adder)
994
    {
995
        $adder->dynamicMethod(1)->willReturn(2);
996
        $adder->dynamicMethod(2)->willReturn(3);
997
998
        $this->beConstructedWith(function () use ($adder) {
999
            yield $adder->dynamicMethod(1);
1000
            yield $adder->dynamicMethod(2);
1001
        });
1002
1003
        $this->realize();
1004
    }
1005
1006
    function it_can_combine_the_collection()
1007
    {
1008
        $this->beConstructedWith(['a', 'b']);
1009
        $this->combine([1, 2])->toArray()->shouldReturn(['a' => 1, 'b' => 2]);
1010
        $this->combine([1])->toArray()->shouldReturn(['a' => 1]);
1011
        $this->combine([1, 2, 3])->toArray()->shouldReturn(['a' => 1, 'b' => 2]);
1012
    }
1013
1014
    function it_can_get_second_item()
1015
    {
1016
        $this->beConstructedWith([1, 2]);
1017
        $this->second()->shouldReturn(2);
1018
    }
1019
1020
    function it_throws_when_trying_to_get_non_existent_second_item()
1021
    {
1022
        $this->beConstructedWith([1]);
1023
        $this->shouldThrow(ItemNotFound::class)->during('second');
1024
    }
1025
1026
    function it_can_drop_item_by_key()
1027
    {
1028
        $this->beConstructedWith(['a' => 1, 'b' => 2]);
1029
        $this->except(['a', 'b'])->toArray()->shouldReturn([]);
1030
    }
1031
1032
    function it_can_get_the_difference_between_collections()
1033
    {
1034
        $this->beConstructedWith([1, 2, 3, 4]);
1035
        $this->diff([1, 2])->toArray()->shouldReturn([2 => 3, 3 => 4]);
1036
        $this->diff([1, 2], [3])->toArray()->shouldReturn([3 => 4]);
1037
    }
1038
1039
    function it_can_flip_the_collection()
1040
    {
1041
        $this->beConstructedWith(['a' => 1, 'b' => 2]);
1042
        $this->flip()->toArray()->shouldReturn([1 => 'a', 2 => 'b']);
1043
    }
1044
1045
    function it_can_check_if_key_exits()
1046
    {
1047
        $this->beConstructedWith(['a' => 1, 'b' => 2]);
1048
        $this->has('a')->shouldReturn(true);
1049
        $this->has('x')->shouldReturn(false);
1050
    }
1051
1052
    function it_filters_by_keys()
1053
    {
1054
        $this->beConstructedWith(['a' => 1, 'b' => 2, 'c' => 3]);
1055
        $this->only(['a', 'b'])->toArray()->shouldReturn(['a' => 1, 'b' => 2]);
1056
        $this->only(['a', 'b', 'x'])->toArray()->shouldReturn(['a' => 1, 'b' => 2]);
1057
    }
1058
1059
    function it_can_serialize_and_unserialize()
1060
    {
1061
        $original = Collection::from([1, 2, 3])->take(2);
1062
        $this->beConstructedWith([1, 2, 3, 4]);
1063
        $this->shouldHaveType(Serializable::class);
1064
        $this->unserialize($original->serialize());
1065
        $this->toArray()->shouldReturn([1, 2]);
1066
    }
1067
1068
    function it_can_zip()
1069
    {
1070
        $this->beConstructedWith([1, 2, 3]);
1071
        $this->zip(['a' => 1, 'b' => 2, 'c' => 4])
1072
            ->map('\DusanKasan\Knapsack\toArray')
1073
            ->toArray()
1074
            ->shouldReturn([[1, 'a' => 1], [1 => 2, 'b' => 2], [2 => 3, 'c' => 4]]);
1075
1076
        $this->zip([4, 5, 6], [7, 8, 9])
1077
            ->map('\DusanKasan\Knapsack\values')
1078
            ->map('\DusanKasan\Knapsack\toArray')
1079
            ->toArray()
1080
            ->shouldReturn([[1, 4, 7], [2, 5, 8], [3, 6, 9]]);
1081
1082
        $this->zip([4, 5])
1083
            ->map('\DusanKasan\Knapsack\values')
1084
            ->map('\DusanKasan\Knapsack\toArray')
1085
            ->toArray()
1086
            ->shouldReturn([[1, 4], [2, 5]]);
1087
    }
1088
1089
    function it_can_use_callable_as_transformer()
1090
    {
1091
        $this->beConstructedWith([1, 2, 3]);
1092
        $this
1093
            ->transform(function (Collection $collection) {
1094
                return $collection->map('\DusanKasan\Knapsack\increment');
1095
            })
1096
            ->toArray()
1097
            ->shouldReturn([2, 3, 4]);
1098
1099
        $this
1100
            ->shouldThrow(InvalidReturnValue::class)
1101
            ->during(
1102
                'transform',
1103
                [
1104
                    function (Collection $collection) {
1105
                        return $collection->first();
1106
                    },
1107
                ]
1108
            );
1109
    }
1110
1111
    function it_can_extract_data_from_nested_collections()
1112
    {
1113
        $input = [
1114
            [
1115
                'a' => [
1116
                    'b' => 1
1117
                ]
1118
            ],
1119
            [
1120
                'a' => [
1121
                    'b' => 2
1122
                ]
1123
            ],
1124
            [
1125
                '*' => [
1126
                    'b' => 3
1127
                ]
1128
            ],
1129
            [
1130
                '.' => [
1131
                    'b' => 4
1132
                ],
1133
                'c' => [
1134
                    'b' => 5
1135
                ],
1136
                [
1137
                    'a'
1138
                ]
1139
            ]
1140
        ];
1141
        $this->beConstructedWith($input);
1142
1143
        $this->extract('')->toArray()->shouldReturn($input);
1144
        $this->extract('a.b')->toArray()->shouldReturn([1, 2]);
1145
        $this->extract('*.b')->toArray()->shouldReturn([1, 2, 3, 4, 5]);
1146
        $this->extract('\*.b')->toArray()->shouldReturn([3]);
1147
        $this->extract('\..b')->toArray()->shouldReturn([4]);
1148
    }
1149
1150
    function it_can_get_the_intersect_of_collections()
1151
    {
1152
        $this->beConstructedWith([1, 2, 3]);
1153
        $this->intersect([1, 2])->values()->toArray()->shouldReturn([1, 2]);
1154
        $this->intersect([1], [3])->values()->toArray()->shouldReturn([1, 3]);
1155
    }
1156
1157 View Code Duplication
    function it_can_check_if_size_is_exactly_n()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1158
    {
1159
        $this->beConstructedWith([1, 2]);
1160
        $this->sizeIs(2)->shouldReturn(true);
1161
        $this->sizeIs(3)->shouldReturn(false);
1162
        $this->sizeIs(0)->shouldReturn(false);
1163
    }
1164
1165 View Code Duplication
    function it_can_check_if_size_is_less_than_n()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1166
    {
1167
        $this->beConstructedWith([1, 2]);
1168
        $this->sizeIsLessThan(0)->shouldReturn(false);
1169
        $this->sizeIsLessThan(2)->shouldReturn(false);
1170
        $this->sizeIsLessThan(3)->shouldReturn(true);
1171
    }
1172
1173 View Code Duplication
    function it_can_check_if_size_is_greater_than_n()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1174
    {
1175
        $this->beConstructedWith([1, 2]);
1176
        $this->sizeIsGreaterThan(2)->shouldReturn(false);
1177
        $this->sizeIsGreaterThan(1)->shouldReturn(true);
1178
        $this->sizeIsGreaterThan(0)->shouldReturn(true);
1179
    }
1180
1181
    function it_can_check_if_size_is_between_n_and_m()
1182
    {
1183
        $this->beConstructedWith([1, 2]);
1184
        $this->sizeIsBetween(1, 3)->shouldReturn(true);
1185
        $this->sizeIsBetween(3, 4)->shouldReturn(false);
1186
        $this->sizeIsBetween(0, 0)->shouldReturn(false);
1187
        $this->sizeIsBetween(3, 1)->shouldReturn(true);
1188
    }
1189
1190
    function it_can_sum_the_collection()
1191
    {
1192
        $this->beConstructedWith([1, 2, 3, 4]);
1193
        $this->sum()->shouldReturn(10);
1194
        $this->append(1.5)->sum()->shouldReturn(11.5);
1195
    }
1196
1197
    function it_can_get_average_of_the_collection()
1198
    {
1199
        $this->beConstructedWith([1, 2, 2, 3]);
1200
        $this->average()->shouldReturn(2);
1201
        $this->append(3)->average()->shouldReturn(2.2);
1202
    }
1203
1204
    function it_will_return_zero_when_average_is_called_on_empty_collection()
1205
    {
1206
        $this->beConstructedWith([]);
1207
        $this->average()->shouldReturn(0);
1208
    }
1209
1210
    function it_can_get_maximal_value_in_the_colleciton()
1211
    {
1212
        $this->beConstructedWith([1, 2, 3, 2]);
1213
        $this->max()->shouldReturn(3);
1214
    }
1215
1216
    function it_will_return_null_when_max_is_called_on_empty_collection()
1217
    {
1218
        $this->beConstructedWith([]);
1219
        $this->max()->shouldReturn(null);
1220
    }
1221
1222
    function it_can_get_min_value_in_the_colleciton()
1223
    {
1224
        $this->beConstructedWith([2, 1, 3, 2]);
1225
        $this->min()->shouldReturn(1);
1226
    }
1227
1228
    function it_will_return_null_when_min_is_called_on_empty_collection()
1229
    {
1230
        $this->beConstructedWith([]);
1231
        $this->min()->shouldReturn(null);
1232
    }
1233
1234
    function it_can_convert_the_collection_to_string()
1235
    {
1236
        $this->beConstructedWith([2, 'a', 3, null]);
1237
        $this->toString()->shouldReturn('2a3');
1238
    }
1239
1240
    function it_can_replace_by_key()
1241
    {
1242
        $this->beConstructedWith(['a' => 1, 'b' => 2, 'c' => 3]);
1243
        $this->replaceByKeys(['b' => 3])->toArray()->shouldReturn(['a' => 1, 'b' => 3, 'c' => 3]);
1244
    }
1245
1246
    function it_can_transpose_collections_of_collections()
1247
    {
1248
        $this->beConstructedWith([
1249
            new Collection([1, 2, 3]),
1250
            new Collection([4, 5, new Collection(['foo', 'bar'])]),
1251
            new Collection([7, 8, 9]),
1252
        ]);
1253
1254
        $this->transpose()->toArray()->shouldBeLike([
1255
            new Collection([1, 4, 7]),
1256
            new Collection([2, 5, 8]),
1257
            new Collection([3, new Collection(['foo', 'bar']), 9]),
1258
        ]);
1259
    }
1260
1261
    function it_can_transpose_arrays_of_different_lengths()
1262
    {
1263
        $this->beConstructedWith([
1264
            new Collection(['a', 'b', 'c', 'd']),
1265
            new Collection(['apple', 'box', 'car']),
1266
        ]);
1267
1268
        $this->transpose()->toArray()->shouldBeLike([
1269
            new Collection(['a', 'apple']),
1270
            new Collection(['b', 'box']),
1271
            new Collection(['c', 'car']),
1272
            new Collection(['d', null]),
1273
        ]);
1274
    }
1275
1276
    function it_should_throw_an_invalid_argument_if_collection_items_are_not_collection()
1277
    {
1278
        $this->beConstructedWith([
1279
            [1, 2, 3],
1280
            [4, 5, 6],
1281
            [7, 8, 9],
1282
        ]);
1283
1284
        $this->shouldThrow(InvalidArgument::class)->during('transpose');
1285
    }
1286
1287
    function it_can_use_the_utility_methods()
1288
    {
1289
        $this->beConstructedWith([1, 3, 2]);
1290
1291
        $this
1292
            ->sort('\DusanKasan\Knapsack\compare')
1293
            ->values()
1294
            ->toArray()
1295
            ->shouldReturn([1, 2, 3]);
1296
1297
        $this
1298
            ->map('\DusanKasan\Knapsack\compare')
1299
            ->toArray()
1300
            ->shouldReturn([1, 1, 0]);
1301
1302
        $this
1303
            ->map('\DusanKasan\Knapsack\decrement')
1304
            ->toArray()
1305
            ->shouldReturn([0, 2, 1]);
1306
    }
1307
1308
    function it_can_dump_the_collection()
1309
    {
1310
        $this->beConstructedWith(
1311
            [
1312
                [
1313
                    [1, [2], 3],
1314
                    ['a' => 'b'],
1315
                    new ArrayIterator([1, 2, 3])
1316
                ],
1317
                [1, 2, 3],
1318
                new ArrayIterator(['a', 'b', 'c']),
1319
                true,
1320
                new \DusanKasan\Knapsack\Tests\Helpers\Car('sedan', 5),
1321
                \DusanKasan\Knapsack\concat([1], [1]),
1322
            ]
1323
        );
1324
1325
        $this->dump()->shouldReturn(
1326
            [
1327
                [
1328
                    [1, [2], 3],
1329
                    ['a' => 'b'],
1330
                    [1, 2, 3]
1331
                ],
1332
                [1, 2, 3],
1333
                ['a', 'b', 'c'],
1334
                true,
1335
                [
1336
                    'DusanKasan\Knapsack\Tests\Helpers\Car' => [
1337
                        'numberOfSeats' => 5,
1338
                     ],
1339
1340
                ],
1341
                [1, '0//1' => 1]
1342
            ]
1343
        );
1344
1345
        $this->dump(2)->shouldReturn(
1346
            [
1347
                [
1348
                    [1, [2], '>>>'],
1349
                    ['a' => 'b'],
1350
                    '>>>'
1351
                ],
1352
                [1, 2, '>>>'],
1353
                '>>>'
1354
            ]
1355
        );
1356
1357
        $this->dump(null, 3)->shouldReturn(
1358
            [
1359
                [
1360
                    [1, '^^^', 3],
1361
                    ['a' => 'b'],
1362
                    [1, 2, 3]
1363
                ],
1364
                [1, 2, 3],
1365
                ['a', 'b', 'c'],
1366
                true,
1367
                [
1368
                    'DusanKasan\Knapsack\Tests\Helpers\Car' => [
1369
                        'numberOfSeats' => 5,
1370
                    ],
1371
                ],
1372
                [1, '0//1' => 1]
1373
            ]
1374
        );
1375
1376
        $this->dump(2, 3)->shouldReturn(
1377
            [
1378
                [
1379
                    [1, '^^^', '>>>'],
1380
                    ['a' => 'b'],
1381
                    '>>>'
1382
                ],
1383
                [1, 2, '>>>'],
1384
                '>>>'
1385
            ]
1386
        );
1387
    }
1388
1389
    function it_can_print_dump()
1390
    {
1391
        $this->beConstructedWith([1, [2], 3]);
1392
1393
        ob_start();
1394
        $this->printDump()->shouldReturn($this);
1395
        $this->printDump(2)->shouldReturn($this);
1396
        $this->printDump(2, 2)->shouldReturn($this);
1397
        ob_clean();
1398
    }
1399
}
1400