I am mocking a chain of methods. I can get it to work fine with PHPUnit's MockBuilder; however, I was wondering if there is a cleaner way to 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, but I would like it to look something like the following code replacing setMethods with 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)
Aucun commentaire:
Enregistrer un commentaire