@@ -159,6 +159,24 @@ public function testStubbedException()
159
159
$ this ->fail ();
160
160
}
161
161
162
+ public function testStubbedWillThrowException ()
163
+ {
164
+ $ mock = $ this ->getMock ('AnInterface ' );
165
+ $ mock ->expects ($ this ->any ())
166
+ ->method ('doSomething ' )
167
+ ->willThrowException (new Exception );
168
+
169
+ try {
170
+ $ mock ->doSomething ();
171
+ }
172
+
173
+ catch (Exception $ e ) {
174
+ return ;
175
+ }
176
+
177
+ $ this ->fail ();
178
+ }
179
+
162
180
public function testStubbedReturnValue ()
163
181
{
164
182
$ mock = $ this ->getMock ('AnInterface ' );
@@ -202,6 +220,23 @@ public function testStubbedReturnValueMap()
202
220
$ this ->assertEquals (NULL , $ mock ->doSomething ('foo ' , 'bar ' ));
203
221
}
204
222
223
+ public function testStubbedReturnArgument ()
224
+ {
225
+ $ mock = $ this ->getMock ('AnInterface ' );
226
+ $ mock ->expects ($ this ->any ())
227
+ ->method ('doSomething ' )
228
+ ->will ($ this ->returnArgument (1 ));
229
+
230
+ $ this ->assertEquals ('b ' , $ mock ->doSomething ('a ' , 'b ' ));
231
+
232
+ $ mock = $ this ->getMock ('AnInterface ' );
233
+ $ mock ->expects ($ this ->any ())
234
+ ->method ('doSomething ' )
235
+ ->willReturnArgument (1 );
236
+
237
+ $ this ->assertEquals ('b ' , $ mock ->doSomething ('a ' , 'b ' ));
238
+ }
239
+
205
240
public function testFunctionCallback ()
206
241
{
207
242
$ mock = $ this ->getMock ('SomeClass ' , array ('doSomething ' ), array (), '' , FALSE );
@@ -219,6 +254,44 @@ public function testFunctionCallback()
219
254
$ this ->assertEquals ('pass ' , $ mock ->doSomething ('foo ' , 'bar ' ));
220
255
}
221
256
257
+ public function testStubbedReturnSelf ()
258
+ {
259
+ $ mock = $ this ->getMock ('AnInterface ' );
260
+ $ mock ->expects ($ this ->any ())
261
+ ->method ('doSomething ' )
262
+ ->will ($ this ->returnSelf ());
263
+
264
+ $ this ->assertEquals ($ mock , $ mock ->doSomething ());
265
+
266
+ $ mock = $ this ->getMock ('AnInterface ' );
267
+ $ mock ->expects ($ this ->any ())
268
+ ->method ('doSomething ' )
269
+ ->willReturnSelf ();
270
+
271
+ $ this ->assertEquals ($ mock , $ mock ->doSomething ());
272
+ }
273
+
274
+ public function testStubbedReturnOnConsecutiveCalls ()
275
+ {
276
+ $ mock = $ this ->getMock ('AnInterface ' );
277
+ $ mock ->expects ($ this ->any ())
278
+ ->method ('doSomething ' )
279
+ ->will ($ this ->onConsecutiveCalls ('a ' , 'b ' , 'c ' ));
280
+
281
+ $ this ->assertEquals ('a ' , $ mock ->doSomething ());
282
+ $ this ->assertEquals ('b ' , $ mock ->doSomething ());
283
+ $ this ->assertEquals ('c ' , $ mock ->doSomething ());
284
+
285
+ $ mock = $ this ->getMock ('AnInterface ' );
286
+ $ mock ->expects ($ this ->any ())
287
+ ->method ('doSomething ' )
288
+ ->willReturnOnConsecutiveCalls ('a ' , 'b ' , 'c ' );
289
+
290
+ $ this ->assertEquals ('a ' , $ mock ->doSomething ());
291
+ $ this ->assertEquals ('b ' , $ mock ->doSomething ());
292
+ $ this ->assertEquals ('c ' , $ mock ->doSomething ());
293
+ }
294
+
222
295
public function testStaticMethodCallback ()
223
296
{
224
297
$ mock = $ this ->getMock ('SomeClass ' , array ('doSomething ' ), array (), '' , FALSE );
0 commit comments