I'm writing a unit test that relies on an external class, exceptionManager. I want to be able to predict what some specific functions on this class will return, so I'm using a mock object. The code is quite straightforward:
$mockExceptionManager = $this->getMock('exceptionManager');
The trouble is, my exception manager implements the IteratorAggregate interface, which requires a method that looks like this:
public function getIterator()
{
return new ArrayIterator($this->exceptions);
}
When I run 开发者_开发问答the unit test, I get the following error:
Fatal error: Cannot redeclare Mock_exceptionManager_ae79bad2::getIterator() in /Applications/MAMP/bin/php5.2/lib/php/PEAR/PHPUnit/Framework/MockObject/Generator.php(170) : eval()'d code on line 297
I have a feeling that the PHPUnit mock object suite also implements the IteratorAggregate interface, and the two are clashing, although I'm unsure. I also tried using the Iterator interface, but ran into the same issue. How can I get around this?
I disabled autoloading on the mock object which solved the issue.
$mockExceptionManager = $this->getMockBuilder('exceptionManager')
->disableAutoload()
->getMock();
精彩评论