Google이 작동하고 반응하는지 테스트 할 필요가 없으며 (수정하지 못하더라도 해결할 수 없음) Zend_OpenId (아직 다루지 않음)를 테스트 할 필요가 없습니다. 자신의 코드 만 테스트해야합니다. OpenId 응답을 스텁하는 것이 좋습니다. 나는 여기에
if (isset($_POST['openid_action']) &&
$_POST['openid_action'] == "login" &&
!empty($_POST['openid_identifier'])) {
$consumer = new Mygoogle_OpenId_Consumer();
if (!$consumer->login($_POST['openid_identifier'])) {
$status = "OpenID login failed.";
}
} else if (isset($_GET['openid_mode'])) {
if ($_GET['openid_mode'] == "id_res") {
$consumer = new Mygoogle_OpenId_Consumer();
if ($consumer->verify($_GET, $id)) {
$status = "VALID " . htmlspecialchars($id);
} else {
$status = "INVALID " . htmlspecialchars($id);
}
} else if ($_GET['openid_mode'] == "cancel") {
$status = "CANCELLED";
}
}
당신이 진짜 구글에 대한 호출뿐만 아니라 테스트 Zend_OpenId_Consumer을하지 않으의이 Mygoogle_OpenId_Consumer 클래스를 사용하여 당신이 젠드 참조 가이드에서 예를 가정 해 봅시다, 코드가 어떻게 보이는지 모르겠어요 그래서 우리는 Zend_OpenId_Consumer를 스텁해야합니다. 클래스에서 스텁을 만들려면 Zend_OpenId_Consumer 또는 mock 객체 인 어댑터를 사용합니다. 당신의 검사 결과에
class Mygoogle_OpenId_Consumer extends Zend_OpenId_Consumer
{
private static $_adapter = null;
public static function setAdapter($adapter)
{
self::$_adapter = $adapter;
}
public static function getAdapter()
{
if (empty(self::$_adapter)) {
self::$_adapter = new Zend_OpenId_Consumer();
}
return self::$_adapter;
}
.....
그리고 마지막으로 우리는 당신에 대한 전체 답변을하지 않습니다하지만 당신이보고 싶을 수도 모의 객체를 생성하고
private function _stubGoogle($successful = false)
{
$adapter = $this->getMock('Mygoogle_OpenId_Consumer', array('login','verify'));
$httpResponse = $successful?:null;
$adapter->expects($this->any())
->method('login')
->will($this->returnValue($httpResponse));
$adapter->expects($this->any())
->method('verify')
->will($this->returnValue($successful));
Mygoogle_OpenId_Consumer::setAdapter($adapter);
}
public function testUserLogsSuccessfullyUsingGoogle()
{
$this->_stubGoogle(true);
//do whatever you need to test your login action:
//set and send request, dispatch your action
}
public function testUserLogsUnSuccessfullyUsingGoogle()
{
$this->_stubGoogle(false);
...
}
스텁을 위해 그것을 사용할 필요가 ZF 내의 Zend_OpenID 컴포넌트에 대한 유닛 테스트. 그것은 당신에게 몇 가지 아이디어를 줄 수 있습니다. –