Created
February 21, 2010 18:51
-
-
Save shupp/310459 to your computer and use it in GitHub Desktop.
Example for attaching mocked dependencies
This file contains 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 | |
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