Created
February 6, 2012 18:22
-
-
Save isidromerayo/1753864 to your computer and use it in GitHub Desktop.
Phake 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 | |
public function testProcessSomeDataLogsExceptions() { | |
$logger = Phake::mock('LOGGER'); | |
$data = Phake::mock('MyData'); | |
$processor = Phake::mock('MyDataProcessor'); | |
Phake::when($processor)->process($data) | |
->thenThrow(new Exception('My error message!')); | |
$sut = new MyClass($logger); | |
$sut->processSomeData($processor, $data); | |
//This comes from the exception we created above | |
Phake::verify($logger)->log('My error message!'); | |
} |
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 = Phake::mock('MyMockedClass'); | |
$mock->fooWithArgument('foo'); | |
$mock->fooWithArgument('bar'); | |
Phake::inOrder( | |
Phake::verify($mock)->fooWithArgument('foo'), | |
Phake::verify($mock)->fooWithArgument('bar') | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment