Skip to content

Instantly share code, notes, and snippets.

@shupp
Created February 21, 2010 18:51
Show Gist options
  • Save shupp/310459 to your computer and use it in GitHub Desktop.
Save shupp/310459 to your computer and use it in GitHub Desktop.
Example for attaching mocked dependencies
<?php
class Auth_Driver_OpenIDTest extends PHPUnit_Framework_TestCase
{
protected function getCache()
{
return $this->getMock('stdClass', array('get', 'set'));
}
protected function getUserClient()
{
return $this->getMock('stdClass', array('getUserByOpenID'));
}
protected function getAuthDriverOpenID($cache, $userClient)
{
$mock = $this->getMock('Auth_Driver_OpenID', array('getCache', 'getUserClient'));
$mock->expects($this->once())
->method('getCache')
->will($this->returnValue($cache));
$mock->expects($this->once())
->method('getUserClient')
->will($this->returnValue($cache));
return $mock;
}
public function testGetUserByOpenIDSuccess()
{
// Dummy user instance
$model = new Model_User(array('id' => 59));
$cache = $this->getCache();
$client = $this->getUserClient();
$client->expects($this->once())
->method('getUserByOpenID')
->will($this->returnValue($model));
$auth = $this->getAuthDriverOpenID($cache, $client);
$this->assertSame($model, $auth->getUserByOpenID('http:://user.example.com'));
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment