1 | <?php |
||
27 | class MockedIteratorTest extends \PHPUnit_Framework_TestCase |
||
28 | { |
||
29 | 6 | protected function mockGenericIteratableList() |
|
33 | |||
34 | /** |
||
35 | * Mock iterator |
||
36 | * |
||
37 | * This attaches all the required expectations in the right order so that |
||
38 | * our iterator will act like an iterator! |
||
39 | * |
||
40 | * @param \Iterator $iterator The iterator object; this is what we attach |
||
41 | * all the expectations to |
||
42 | * @param array An array of items that we will mock up, we will use the |
||
43 | * keys (if needed) and values of this array to return |
||
44 | * @param boolean $includeCallsToKey Whether we want to mock up the calls |
||
45 | * to "key"; only needed if you are doing foreach ($foo as $k => $v) |
||
46 | * as opposed to foreach ($foo as $v) |
||
47 | */ |
||
48 | 4 | protected function mockIterator( |
|
49 | \Iterator $iterator, |
||
50 | array $items, |
||
51 | $includeCallsToKey = FALSE |
||
52 | ) { |
||
53 | $iterator |
||
54 | 4 | ->expects( |
|
55 | 4 | $this->at(0) |
|
56 | ) |
||
57 | 4 | ->method('rewind') |
|
58 | ; |
||
59 | 4 | $counter = 1; |
|
60 | |||
61 | 4 | foreach ($items as $k => $v) { |
|
62 | $iterator |
||
63 | 4 | ->expects( |
|
64 | 4 | $this->at($counter++) |
|
65 | ) |
||
66 | 4 | ->method('valid') |
|
67 | 4 | ->will( |
|
68 | 4 | $this->returnValue(TRUE) |
|
69 | ) |
||
70 | ; |
||
71 | $iterator |
||
72 | 4 | ->expects( |
|
73 | 4 | $this->at($counter++) |
|
74 | ) |
||
75 | 4 | ->method('current') |
|
76 | 4 | ->will( |
|
77 | 4 | $this->returnValue($v) |
|
78 | ) |
||
79 | ; |
||
80 | 4 | if ($includeCallsToKey) { |
|
81 | $iterator |
||
82 | 2 | ->expects( |
|
83 | 2 | $this->at($counter++) |
|
84 | ) |
||
85 | 2 | ->method('key') |
|
86 | 2 | ->will( |
|
87 | 2 | $this->returnValue($k) |
|
88 | ) |
||
89 | ; |
||
90 | } |
||
91 | $iterator |
||
92 | 4 | ->expects( |
|
93 | 4 | $this->at($counter++) |
|
94 | ) |
||
95 | 4 | ->method('next') |
|
96 | ; |
||
97 | } |
||
98 | |||
99 | $iterator |
||
100 | 4 | ->expects( |
|
101 | 4 | $this->at($counter) |
|
102 | ) |
||
103 | 4 | ->method('valid') |
|
104 | 4 | ->will( |
|
105 | 4 | $this->returnValue(FALSE) |
|
106 | ) |
||
107 | ; |
||
108 | 4 | } |
|
109 | |||
110 | 1 | public function testConstructs() |
|
116 | |||
117 | 1 | public function testHasZeroItemsWhenWeHaventMockedMethods() |
|
128 | |||
129 | 1 | public function testWhenMockOneIterationWithNoKey() |
|
142 | |||
143 | 1 | public function testWhenMockOneIterationWithKey() |
|
157 | |||
158 | 1 | public function testWhenMockThreeIterationWithNoKey() |
|
179 | |||
180 | 1 | public function testWhenMockThreeIterationWithKey() |
|
201 | } |
||
202 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.