PHPUnit如何mock函数内部实例化的对象

WBOY
Release: 2016-06-23 13:54:51
Original
1393 people have browsed it

class cash{    public function __construct(){}    public function isCashed(){       //do something        return 1;    }}class sendMsg{    public function send(){          $cash = new cash();          $isCashed = $cash->isCashed();          return $isCashed;         //do something    }}
Copy after login

我想要对上面的sendMsg进行测试的时候 请问怎样mock出cash类然后注入到sendMsg当中

class sendMsgTest extension PHPUnit_Framework_TestCase{             public function testSend(){             $sendMsg = new sendMsg();                          //如何mock一个cash      }}
Copy after login


回复讨论(解决方案)

class cash 这个已经定义好了吗,还是没有定义?

class cash 这个已经定义好了吗,还是没有定义?

 都已经定义好了,是对现有代码写测试,上面那个只是我简化了的个东西

可以试试phpunit phpmock

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template