diff --git a/doc/recipes.rst b/doc/recipes.rst index 9523fff9b..ddc697569 100644 --- a/doc/recipes.rst +++ b/doc/recipes.rst @@ -30,7 +30,7 @@ catches deprecation notices, and return them. .. tip:: If your templates are not stored on the filesystem, use the ``collect()`` - method instead which takes an ``Iterator``; the iterator must return + method instead. ``collect()`` takes a ``Traversable`` which must return template names as keys and template contents as values (as done by ``Twig_Util_TemplateDirIterator``). diff --git a/lib/Twig/Util/DeprecationCollector.php b/lib/Twig/Util/DeprecationCollector.php index f8e1adba5..884cf055f 100644 --- a/lib/Twig/Util/DeprecationCollector.php +++ b/lib/Twig/Util/DeprecationCollector.php @@ -46,11 +46,11 @@ class Twig_Util_DeprecationCollector /** * Returns deprecations for passed templates. * - * @param Iterator $iterator An iterator of templates (where keys are template names and values the contents of the template) + * @param Traversable $iterator An iterator of templates (where keys are template names and values the contents of the template) * * @return array An array of deprecations */ - public function collect(Iterator $iterator) + public function collect(Traversable $iterator) { $this->deprecations = array(); diff --git a/test/Twig/Tests/Util/DeprecationCollectorTest.php b/test/Twig/Tests/Util/DeprecationCollectorTest.php new file mode 100644 index 000000000..9f7d14d17 --- /dev/null +++ b/test/Twig/Tests/Util/DeprecationCollectorTest.php @@ -0,0 +1,42 @@ +getMockBuilder('Twig_LoaderInterface')->getMock()); + $twig->addFunction(new Twig_SimpleFunction('deprec', array($this, 'deprec'), array('deprecated' => true))); + + $collector = new Twig_Util_DeprecationCollector($twig); + $deprecations = $collector->collect(new Twig_Tests_Util_Iterator()); + + $this->assertEquals(array('Twig Function "deprec" is deprecated in deprec.twig at line 1.'), $deprecations); + } + + public function deprec() + { + } +} + +class Twig_Tests_Util_Iterator implements IteratorAggregate +{ + public function getIterator() + { + return new ArrayIterator(array( + 'ok.twig' => '{{ foo }}', + 'deprec.twig' => '{{ deprec("foo") }}', + )); + } +}