How to prevent rewriting errors when using Mock classes that implement the IteratorAggregate interface when testing with PHPUnit?

I am writing a unit test that relies on an external class, exceptionManager. I want to be able to predict that some specific functions in this class will return, so I am using an object layout. The code is pretty simple:

$mockExceptionManager = $this->getMock('exceptionManager');

The problem is that 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 unit test, I get the following error:

Fatal error: Unable to update Mock_exceptionManager_ae79bad2 :: getIterator () in / Applications / MAMP / bin / php 5.2 / lib / php / PEAR / PHPUnit / Framework / MockObject / Generator.php (170): eval () 'd code in line 297

, PHPUnit mock object IteratorAggregate, , . Iterator, . ?

+3
1

-, .

$mockExceptionManager = $this->getMockBuilder('exceptionManager')
                             ->disableAutoload()
                             ->getMock();
+7

Source: https://habr.com/ru/post/1794273/


All Articles