【发布时间】:2014-09-18 12:46:21
【问题描述】:
有如下类:
class MyClass{
public static function create($data){
$dataModified= $self::doCurlRequest($data);
//doing something else with data
return $dataModifiedAlot;
}
public static function doCurlRequest($someData){
//doing request here
}
}
是否可以只模拟 doCurlRequest($someData)?我试过这个:
class MyClassTest extends PHPUnit_Framework_TestCase{
public function testCreate(){
$mock = $this->getMockBuilder('MyClass')->setMethods(array('doCurlRequest'))->getMock();
$mock::staticExpects($this->any())
->method('doCurlRequest')
->with($someDataNeededForRequest)
->will($this->returnValue("some JSON rensponse"));
$response = $mock::create($data);
}
}
问题是 doCurlRequest($someData) 方法返回实际值而不是预期值:/ 我做错了什么?
【问题讨论】:
标签: php mocking phpunit static-methods