【发布时间】:2011-11-10 18:03:43
【问题描述】:
例如,如何使我的存根像 ArrayIterator 一样工作?我的意思是,我想迭代这个存根。这是 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!)
谢谢。
【问题讨论】:
-
对 FibonacciIterator 的正常调用是什么样的?
-
它实现了一个迭代器。你调用 $a = new FibonacciIterator(7)。之后您可以迭代 0、1、1、2、3、5、8。谢谢。
-
该任务实际上不是说“使用 ArrayIterator 作为 FibonacciIterator 的存根”吗?
-
在测试前教写代码的指南是什么样的?!
标签: php unit-testing mocking phpunit stub