Skip to content
This repository was archived by the owner on Feb 20, 2023. It is now read-only.

Commit 22cb30b

Browse files
committed
Added tests for simple will* methods
1 parent 5184fd5 commit 22cb30b

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

Tests/MockObjectTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ public function testStubbedReturnValue()
167167
->will($this->returnValue('something'));
168168

169169
$this->assertEquals('something', $mock->doSomething());
170+
171+
$mock = $this->getMock('AnInterface');
172+
$mock->expects($this->any())
173+
->method('doSomething')
174+
->willReturn('something');
175+
176+
$this->assertEquals('something', $mock->doSomething());
170177
}
171178

172179
public function testStubbedReturnValueMap()
@@ -184,6 +191,15 @@ public function testStubbedReturnValueMap()
184191
$this->assertEquals('d', $mock->doSomething('a', 'b', 'c'));
185192
$this->assertEquals('h', $mock->doSomething('e', 'f', 'g'));
186193
$this->assertEquals(NULL, $mock->doSomething('foo', 'bar'));
194+
195+
$mock = $this->getMock('AnInterface');
196+
$mock->expects($this->any())
197+
->method('doSomething')
198+
->willReturnMap($map);
199+
200+
$this->assertEquals('d', $mock->doSomething('a', 'b', 'c'));
201+
$this->assertEquals('h', $mock->doSomething('e', 'f', 'g'));
202+
$this->assertEquals(NULL, $mock->doSomething('foo', 'bar'));
187203
}
188204

189205
public function testFunctionCallback()
@@ -194,6 +210,13 @@ public function testFunctionCallback()
194210
->will($this->returnCallback('functionCallback'));
195211

196212
$this->assertEquals('pass', $mock->doSomething('foo', 'bar'));
213+
214+
$mock = $this->getMock('SomeClass', array('doSomething'), array(), '', FALSE);
215+
$mock->expects($this->once())
216+
->method('doSomething')
217+
->willReturnCallback('functionCallback');
218+
219+
$this->assertEquals('pass', $mock->doSomething('foo', 'bar'));
197220
}
198221

199222
public function testStaticMethodCallback()
@@ -304,6 +327,21 @@ public function testStubbedReturnValueForStaticMethod()
304327
$this->assertEquals(
305328
'something', StaticMockTestClassMock::doSomething()
306329
);
330+
331+
$this->getMockClass(
332+
'StaticMockTestClass',
333+
array('doSomething'),
334+
array(),
335+
'StaticMockTestClassMock'
336+
);
337+
338+
StaticMockTestClassMock::staticExpects($this->any())
339+
->method('doSomething')
340+
->willReturn('something');
341+
342+
$this->assertEquals(
343+
'something', StaticMockTestClassMock::doSomething()
344+
);
307345
}
308346

309347
public function testStubbedReturnValueForStaticMethod2()
@@ -322,6 +360,21 @@ public function testStubbedReturnValueForStaticMethod2()
322360
$this->assertEquals(
323361
'something', StaticMockTestClassMock2::doSomethingElse()
324362
);
363+
364+
$this->getMockClass(
365+
'StaticMockTestClass',
366+
array('doSomething'),
367+
array(),
368+
'StaticMockTestClassMock2'
369+
);
370+
371+
StaticMockTestClassMock2::staticExpects($this->any())
372+
->method('doSomething')
373+
->willReturn('something');
374+
375+
$this->assertEquals(
376+
'something', StaticMockTestClassMock2::doSomethingElse()
377+
);
325378
}
326379

327380
public function testGetMockForAbstractClass()

0 commit comments

Comments
 (0)