Skip to content

Instantly share code, notes, and snippets.

@isidromerayo
Created February 6, 2012 18:25
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/1753881 to your computer and use it in GitHub Desktop.
Save isidromerayo/1753881 to your computer and use it in GitHub Desktop.
PHPUnit Mock examples
<?php
/**
* @expectedException RuntimeException
*/
public function testThrowExceptionStub()
{
$stub = $this->getMock('SomeClass');
$stub->expects($this->any())
->method('doSomething')
->will($this->throwException(new RuntimeException));
$stub->doSomething();
}
<?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