Sunday, 15 February 2015

php - PHPUnit stub only works for the first method -



php - PHPUnit stub only works for the first method -

i'm trying stub amazon's instance metadata class because calls internal url works within ec2 instance , can't called outside. problem method "send" not recognized. method "get" works fine though. error fatal error: phone call undefined method stub\amazon\stubinstancemetadata::send() in ...etc, etc

$stub = $this->getmockbuilder('aws\common\instancemetadata\instancemetadataclient') ->disableoriginalconstructor() ->getmock(); $stub->expects($this->any()) ->method('get') ->will($this->returnvalue($this)); $stub->expects($this->any()) ->method('send') ->will($this->returnvalue(json_encode(array('test' => 'value'))));

edit: ended beingness combination of 2 different issues. first 1 beingness 1 pointed out @fab. sec beingness homecoming reference $this, phpunit has it's own method, should have done this:

$stub->expects($this->any()) ->method('get') ->will($this->returnself()); // don't utilize returnvalue() here

i don't know original class looks send not method of rather called via magic __call. if want mock it, have explicitly:

...->getmock(array('get', 'send'));

php phpunit

No comments:

Post a Comment