Skip to content

Instantly share code, notes, and snippets.

@isidromerayo
Created February 6, 2012 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isidromerayo/1753864 to your computer and use it in GitHub Desktop.
Save isidromerayo/1753864 to your computer and use it in GitHub Desktop.
Phake examples
<?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!');
}
<?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