How do I make my stub act like an ArrayIterator, for example? I mean, I want to iterate over this stub. It’s an exercise from Practical PHP Testing.
7.2
Write a EvenIterator which takes a FibonacciIterator an iterates only
on the even-indexed values (returning 0, 1, 3, 8, 21...).
7.3
Write tests for the EvenIterator class, stubbing out the
FibonacciIterator using an ArrayIterator in substitution, which is provided
by the Spl (otherwise it will never terminate!)
Thanks.
If I understand correctly the task here is to test
EvenIteratorby usingArrayIteratoras a stub forFibonacciIterator.So for example load
ArrayIteratorwith array of even values, pass it toEvenIteratorand you should get same values. Then do the same with array of odd values, and you should get empty resultset.As you can see, there’s a lot of duplicated code, so some refactoring would be in place.