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