@@ -85,130 +85,14 @@ public function testAppendThrowsException()
8585 $ iterator ->rewind ();
8686
8787 $ iterator ->asort ();
88-
89- }
90-
91- /**
92- * @expectedException MongoDB\Exception\BadMethodCallException
93- * @expectedExceptionMessage MongoDB\Model\TypeMapArrayIterator is immutable
94- */
95- public function testAsortThrowsException ()
96- {
97- $ document = [
98- 'array ' => [1 , 2 , 3 ],
99- 'object ' => ['foo ' => 'bar ' ],
100- ];
101-
102- $ typeMap = [
103- 'root ' => 'object ' ,
104- 'document ' => 'object ' ,
105- 'array ' => 'array ' ,
106- ];
107-
108- $ iterator = new TypeMapArrayIterator ([$ document ], $ typeMap );
109-
110- $ expectedDocument = (object ) [
111- 'array ' => [1 , 2 , 3 ],
112- 'object ' => (object ) ['foo ' => 'bar ' ],
113- ];
114-
115- $ iterator ->rewind ();
116-
117- $ iterator ->asort ();
118- }
119-
120- /**
121- * @expectedException MongoDB\Exception\BadMethodCallException
122- * @expectedExceptionMessage MongoDB\Model\TypeMapArrayIterator is immutable
123- */
124- public function testKsortThrowsException ()
125- {
126- $ document = [
127- 'array ' => [1 , 2 , 3 ],
128- 'object ' => ['foo ' => 'bar ' ],
129- ];
130-
131- $ typeMap = [
132- 'root ' => 'object ' ,
133- 'document ' => 'object ' ,
134- 'array ' => 'array ' ,
135- ];
136-
137- $ iterator = new TypeMapArrayIterator ([$ document ], $ typeMap );
138-
139- $ expectedDocument = (object ) [
140- 'array ' => [1 , 2 , 3 ],
141- 'object ' => (object ) ['foo ' => 'bar ' ],
142- ];
143-
144- $ iterator ->rewind ();
145-
146- $ iterator ->ksort ();
147- }
148-
149- /**
150- * @expectedException MongoDB\Exception\BadMethodCallException
151- * @expectedExceptionMessage MongoDB\Model\TypeMapArrayIterator is immutable
152- */
153- public function testNatcasessortThrowsException ()
154- {
155- $ document = [
156- 'array ' => [1 , 2 , 3 ],
157- 'object ' => ['foo ' => 'bar ' ],
158- ];
159-
160- $ typeMap = [
161- 'root ' => 'object ' ,
162- 'document ' => 'object ' ,
163- 'array ' => 'array ' ,
164- ];
165-
166- $ iterator = new TypeMapArrayIterator ([$ document ], $ typeMap );
167-
168- $ expectedDocument = (object ) [
169- 'array ' => [1 , 2 , 3 ],
170- 'object ' => (object ) ['foo ' => 'bar ' ],
171- ];
172-
173- $ iterator ->rewind ();
174-
175- $ iterator ->natcasesort ();
176- }
177-
178- /**
179- * @expectedException MongoDB\Exception\BadMethodCallException
180- * @expectedExceptionMessage MongoDB\Model\TypeMapArrayIterator is immutable
181- */
182- public function testNatsortThrowsException ()
183- {
184- $ document = [
185- 'array ' => [1 , 2 , 3 ],
186- 'object ' => ['foo ' => 'bar ' ],
187- ];
188-
189- $ typeMap = [
190- 'root ' => 'object ' ,
191- 'document ' => 'object ' ,
192- 'array ' => 'array ' ,
193- ];
194-
195- $ iterator = new TypeMapArrayIterator ([$ document ], $ typeMap );
196-
197- $ expectedDocument = (object ) [
198- 'array ' => [1 , 2 , 3 ],
199- 'object ' => (object ) ['foo ' => 'bar ' ],
200- ];
201-
202- $ iterator ->rewind ();
203-
204- $ iterator ->natsort ();
20588 }
20689
20790 /**
91+ * @dataProvider provideMutateMethods
20892 * @expectedException MongoDB\Exception\BadMethodCallException
20993 * @expectedExceptionMessage MongoDB\Model\TypeMapArrayIterator is immutable
21094 */
211- public function testOffsetSetThrowsException ( )
95+ public function testMutateMethodsCannotBeCalled ( $ method , $ args )
21296 {
21397 $ document = [
21498 'array ' => [1 , 2 , 3 ],
@@ -223,104 +107,23 @@ public function testOffsetSetThrowsException()
223107
224108 $ iterator = new TypeMapArrayIterator ([$ document ], $ typeMap );
225109
226- $ expectedDocument = (object ) [
227- 'array ' => [1 , 2 , 3 ],
228- 'object ' => (object ) ['foo ' => 'bar ' ],
229- ];
230-
231110 $ iterator ->rewind ();
232111
233- $ iterator-> offsetSet ( 0 , 3 );
112+ call_user_func_array ([ $ iterator, $ method ], $ args );
234113 }
235114
236- /**
237- * @expectedException MongoDB\Exception\BadMethodCallException
238- * @expectedExceptionMessage MongoDB\Model\TypeMapArrayIterator is immutable
239- */
240- public function testOffsetUnsetThrowsException ()
115+ public function provideMutateMethods ()
241116 {
242- $ document = [
243- 'array ' => [1 , 2 , 3 ],
244- 'object ' => ['foo ' => 'bar ' ],
245- ];
246-
247- $ typeMap = [
248- 'root ' => 'object ' ,
249- 'document ' => 'object ' ,
250- 'array ' => 'array ' ,
251- ];
252-
253- $ iterator = new TypeMapArrayIterator ([$ document ], $ typeMap );
254-
255- $ expectedDocument = (object ) [
256- 'array ' => [1 , 2 , 3 ],
257- 'object ' => (object ) ['foo ' => 'bar ' ],
117+ return [
118+ ['append ' , [['x ' => 1 ]]],
119+ ['asort ' , []],
120+ ['ksort ' , []],
121+ ['natcasesort ' , []],
122+ ['natsort ' , []],
123+ ['offsetSet ' , [0 , ['x ' => 1 ]]],
124+ ['offsetUnset ' , [0 ]],
125+ ['uasort ' , [function ($ a , $ b ) { return 0 ; }]],
126+ ['uksort ' , [function ($ a , $ b ) { return 0 ; }]],
258127 ];
259-
260- $ iterator ->rewind ();
261-
262- $ iterator ->offsetUnset (0 );
263- }
264-
265- /**
266- * @expectedException MongoDB\Exception\BadMethodCallException
267- * @expectedExceptionMessage MongoDB\Model\TypeMapArrayIterator is immutable
268- */
269- public function testUasortThrowsException ()
270- {
271- $ document = [
272- 'array ' => [1 , 2 , 3 ],
273- 'object ' => ['foo ' => 'bar ' ],
274- ];
275-
276- $ typeMap = [
277- 'root ' => 'object ' ,
278- 'document ' => 'object ' ,
279- 'array ' => 'array ' ,
280- ];
281-
282- $ iterator = new TypeMapArrayIterator ([$ document ], $ typeMap );
283-
284- $ expectedDocument = (object ) [
285- 'array ' => [1 , 2 , 3 ],
286- 'object ' => (object ) ['foo ' => 'bar ' ],
287- ];
288-
289- $ iterator ->rewind ();
290- $ cmp_function = function ($ a , $ b ) {
291- return $ a ;
292- };
293- $ iterator ->uasort ($ cmp_function (0 , 1 ));
294- }
295-
296- /**
297- * @expectedException MongoDB\Exception\BadMethodCallException
298- * @expectedExceptionMessage MongoDB\Model\TypeMapArrayIterator is immutable
299- */
300- public function testUksortThrowsException ()
301- {
302- $ document = [
303- 'array ' => [1 , 2 , 3 ],
304- 'object ' => ['foo ' => 'bar ' ],
305- ];
306-
307- $ typeMap = [
308- 'root ' => 'object ' ,
309- 'document ' => 'object ' ,
310- 'array ' => 'array ' ,
311- ];
312-
313- $ iterator = new TypeMapArrayIterator ([$ document ], $ typeMap );
314-
315- $ expectedDocument = (object ) [
316- 'array ' => [1 , 2 , 3 ],
317- 'object ' => (object ) ['foo ' => 'bar ' ],
318- ];
319-
320- $ iterator ->rewind ();
321- $ cmp_function = function ($ a , $ b ) {
322- return $ a ;
323- };
324- $ iterator ->uksort ($ cmp_function (0 , 1 ));
325128 }
326129}
0 commit comments