php - Is there a setMethods() Equivalent in Mockery for Mocking Chained Methods -
i mocking chain of methods. can work fine phpunit's mockbuilder; however, wondering if there cleaner way mock them in mockery.
my current code looks like:
$this->repositorymock = $this->getmockbuilder('repository') ->setmethods(array('method1', 'method2', 'method3')) ->getmock(); $this->repositorymock->expects($this->any()) ->method('method1') ->will($this->returnself()); $this->repositorymock->expects($this->any()) ->method('method2') ->will($this->returnvalue(true)); $this->repositorymock->expects($this->any()) ->method('method3') ->will($this->returnvalue(true));
setmethods won't work when using mockery::mock, following code replacing setmethods mockery's version:
$this->repositorymock = mockery::mock('repository') ->setmethods('method1', 'method2', 'method3'); $this->repositorymock ->shouldreceive('method1') ->andreturn($this->returnself()) ->shouldreceive('method2') ->andreturn(true) ->shouldreceive('method3') ->andreturn(true)
i figured out , setmethods() not necessary , can chained fine without.
$this->repositorymock = mockery::mock('repository'); $this->repositorymock ->shouldreceive('method1') ->andreturn($this->returnself()) ->shouldreceive('method2') ->andreturn(true) ->shouldreceive('method3') ->andreturn(true)
Comments
Post a Comment