Merge branch '1.x' into 2.x

* 1.x:
  added some missing tests
This commit is contained in:
Fabien Potencier
2017-02-21 18:52:53 -08:00
3 changed files with 45 additions and 3 deletions
+1 -1
View File
@@ -27,7 +27,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``).
+2 -2
View File
@@ -43,11 +43,11 @@ final 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)
{
$deprecations = array();
set_error_handler(function ($type, $msg) use (&$deprecations) {
@@ -0,0 +1,42 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Twig_Tests_Util_DeprecationCollectorTest extends PHPUnit_Framework_TestCase
{
/**
* @requires PHP 5.3
*/
public function testCollect()
{
$twig = new Twig_Environment($this->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") }}',
));
}
}