测试使用 Twitter API 的 Zend_Controller
我正在尝试为我的控制器编写一个单元测试,它使用 Zend_Service 调用 Twitter API。
/**
* Authenticate Step 1 for Twitter
*/
public function authenticateAction()
{
$this->service->authenticate();
}
该服务确实:
/**
* Authenticate with twitter
*
* @return void
*/
public function authenticate()
{
$consumer = new Zend_Oauth_Consumer($this->config);
$token = $consumer->getRequestToken();
$this->session->twitterRequestToken = serialize($token);
$consumer->redirect();
exit;
}
我的问题是我不知道如何替换服务内的身份验证操作以进行单元测试。我不想在测试运行时调用 Twitter API。
有没有可以做这样的事情的模拟框架?
I'm trying to write a unit test for my Controller which calls the Twitter API using Zend_Service.
/**
* Authenticate Step 1 for Twitter
*/
public function authenticateAction()
{
$this->service->authenticate();
}
The Service does:
/**
* Authenticate with twitter
*
* @return void
*/
public function authenticate()
{
$consumer = new Zend_Oauth_Consumer($this->config);
$token = $consumer->getRequestToken();
$this->session->twitterRequestToken = serialize($token);
$consumer->redirect();
exit;
}
My Problem is that I have no idea how to replace the authenticate action inside the service for the unit test. I don't want to call the Twitter API while the tests run.
Is there any Mocking Framework which can do such things?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Zend_Service_Twitter 使用 Zend_Http_Client 所以你可以在你的测试用例中存根它
Zend_Service_Twitter uses Zend_Http_Client so you can stub it in your test case