1 | <?php |
||
18 | class AddCollectionTest extends UnitTestCase |
||
19 | { |
||
20 | public function testAddAppendsItemToCollectionWithNextNumericIndex() |
||
21 | { |
||
22 | $array = Factory::create($this->fixtures['array']); |
||
23 | $this->assertEquals( |
||
24 | [ |
||
25 | 0 => 'first', |
||
26 | 1 => 'second', |
||
27 | 2 => 'third', |
||
28 | ], |
||
29 | $array->toArray() |
||
30 | ); |
||
31 | $array->add('fourth'); |
||
32 | $this->assertSame( |
||
33 | [ |
||
34 | 0 => 'first', |
||
35 | 1 => 'second', |
||
36 | 2 => 'third', |
||
37 | 3 => 'fourth', |
||
38 | ], |
||
39 | $array->toArray() |
||
40 | ); |
||
41 | $array->add('fifth'); |
||
42 | $this->assertSame( |
||
43 | [ |
||
44 | 0 => 'first', |
||
45 | 1 => 'second', |
||
46 | 2 => 'third', |
||
47 | 3 => 'fourth', |
||
48 | 4 => 'fifth', |
||
49 | ], |
||
50 | $array->toArray() |
||
51 | ); |
||
52 | |||
53 | $assoc = Factory::create($this->fixtures['assoc']); |
||
54 | $this->assertEquals( |
||
55 | [ |
||
56 | '1st' => 'first', |
||
57 | '2nd' => 'second', |
||
58 | '3rd' => 'third', |
||
59 | ], |
||
60 | $assoc->toArray() |
||
61 | ); |
||
62 | $assoc->add('fourth'); |
||
63 | $this->assertSame( |
||
64 | [ |
||
65 | '1st' => 'first', |
||
66 | '2nd' => 'second', |
||
67 | '3rd' => 'third', |
||
68 | 0 => 'fourth', |
||
69 | ], |
||
70 | $assoc->toArray() |
||
71 | ); |
||
72 | $assoc->add('fifth'); |
||
73 | $this->assertSame( |
||
74 | [ |
||
75 | '1st' => 'first', |
||
76 | '2nd' => 'second', |
||
77 | '3rd' => 'third', |
||
78 | 0 => 'fourth', |
||
79 | 1 => 'fifth', |
||
80 | ], |
||
81 | $assoc->toArray() |
||
82 | ); |
||
83 | } |
||
84 | } |
||
85 |