1 | <?php |
||
18 | class IteratorCollectionTest extends UnitTestCase |
||
19 | { |
||
20 | public function testCurrentReturnsCurrentValue() |
||
25 | |||
26 | public function testNextMovesCollectionInternalPointer() |
||
27 | { |
||
28 | $coll = Factory::create($this->fixtures['names']); |
||
29 | $this->assertEquals( |
||
30 | 'Chelsea', |
||
31 | $coll->current(), |
||
32 | 'Initial call to current() should return first item in collection.' |
||
33 | ); |
||
34 | $this->assertEquals( |
||
35 | 'Chelsea', |
||
36 | $coll->current(), |
||
37 | 'Subsequent calls to current() should continue to return the same value.' |
||
38 | ); |
||
39 | $coll->next(); |
||
40 | $this->assertEquals( |
||
41 | 'Adella', |
||
42 | $coll->current(), |
||
43 | 'After calling next(), current() should return the next item in the collection.' |
||
44 | ); |
||
45 | $coll->next(); |
||
46 | $this->assertEquals( |
||
47 | 'Monte', |
||
48 | $coll->current(), |
||
49 | 'Subsequent calls to next() and current() should return the next item in the collection.' |
||
50 | ); |
||
51 | $coll->next(); |
||
52 | $coll->next(); |
||
53 | $coll->next(); |
||
54 | $coll->next(); |
||
55 | $coll->next(); |
||
56 | $coll->next(); |
||
57 | $coll->next(); |
||
58 | $this->assertEquals('Nakia', $coll->current(), 'We should now be at the last item in the collection.'); |
||
59 | $coll->next(); |
||
60 | $this->assertFalse( |
||
61 | $coll->current(), |
||
62 | "Subsequent calls to current() should return false because we have next'd past the end of the collection." |
||
63 | ); |
||
64 | $coll->next(); |
||
65 | $this->assertFalse( |
||
66 | $coll->current(), |
||
67 | "Subsequent calls to current() should return false because we have next'd past the end of the collection." |
||
68 | ); |
||
69 | } |
||
70 | |||
71 | public function testKeyReturnsCurrentKeyInCollection() |
||
72 | { |
||
73 | $coll = Factory::create($this->fixtures['names']); |
||
74 | $this->assertSame(0, $coll->key(), 'Initial call to key() should return first item in collection.'); |
||
75 | $this->assertSame(0, $coll->key(), 'Subsequent calls to key() should continue to return the same value.'); |
||
76 | $coll->next(); |
||
77 | $this->assertSame( |
||
78 | 1, |
||
79 | $coll->key(), |
||
80 | 'After calling next(), key() should return the next item in the collection.' |
||
81 | ); |
||
82 | $coll->next(); |
||
83 | $this->assertSame( |
||
84 | 2, |
||
85 | $coll->key(), |
||
86 | 'Subsequent calls to next() and key() should return the next item in the collection.' |
||
87 | ); |
||
88 | $coll->next(); |
||
89 | $coll->next(); |
||
90 | $coll->next(); |
||
91 | $coll->next(); |
||
92 | $coll->next(); |
||
93 | $coll->next(); |
||
94 | $coll->next(); |
||
95 | $this->assertSame(9, $coll->key(), 'We should now be at the last item in the collection.'); |
||
96 | $coll->next(); |
||
97 | $this->assertNull( |
||
98 | $coll->key(), |
||
99 | 'Subsequent calls to key() should continue to return null because'. |
||
100 | " we have next'd past the end of the collection." |
||
101 | ); |
||
102 | $coll->next(); |
||
103 | $this->assertNull( |
||
104 | $coll->key(), |
||
105 | 'Subsequent calls to key() should continue to return null because'. |
||
106 | " we have next'd past the end of the collection." |
||
107 | ); |
||
108 | } |
||
109 | |||
110 | public function testValidReturnsFalseWhenCollectionHasBeenIteratedBeyondItsLastItem() |
||
132 | |||
133 | public function testRewindWillReturnInternalPointerToItsInitialPosition() |
||
172 | |||
173 | public function testInstantiationShouldRewindArrayArgsInternalPointer() |
||
182 | } |
||
183 |