Created
February 6, 2012 18:25
-
-
Save isidromerayo/1753881 to your computer and use it in GitHub Desktop.
PHPUnit Mock examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @expectedException RuntimeException | |
*/ | |
public function testThrowExceptionStub() | |
{ | |
$stub = $this->getMock('SomeClass'); | |
$stub->expects($this->any()) | |
->method('doSomething') | |
->will($this->throwException(new RuntimeException)); | |
$stub->doSomething(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function testPHPUnitMock() | |
{ | |
$mock = $this->getMock('MyMockedClass'); | |
$mock->expects($this->at(0))->method('fooWithArgument')->with('foo'); | |
$mock->expects($this->at(1))->method('fooWithArgument')->with('bar'); | |
$mock->fooWithArgument('foo'); | |
$mock->fooWithArgument('bar'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment