Browse code

Merge branch '1.x' into 2.x

* 1.x:
added some missing tests

Fabien Potencier authored on 22/02/2017 02:52:53
Showing 3 changed files
... ...
@@ -27,7 +27,7 @@ catches deprecation notices, and return them.
27 27
 .. tip::
28 28
 
29 29
     If your templates are not stored on the filesystem, use the ``collect()``
30
-    method instead which takes an ``Iterator``; the iterator must return
30
+    method instead. ``collect()`` takes a ``Traversable`` which must return
31 31
     template names as keys and template contents as values (as done by
32 32
     ``Twig_Util_TemplateDirIterator``).
33 33
 
... ...
@@ -43,11 +43,11 @@ final class Twig_Util_DeprecationCollector
43 43
     /**
44 44
      * Returns deprecations for passed templates.
45 45
      *
46
-     * @param Iterator $iterator An iterator of templates (where keys are template names and values the contents of the template)
46
+     * @param Traversable $iterator An iterator of templates (where keys are template names and values the contents of the template)
47 47
      *
48 48
      * @return array An array of deprecations
49 49
      */
50
-    public function collect(Iterator $iterator)
50
+    public function collect(Traversable $iterator)
51 51
     {
52 52
         $deprecations = array();
53 53
         set_error_handler(function ($type, $msg) use (&$deprecations) {
54 54
new file mode 100644
... ...
@@ -0,0 +1,42 @@
1
+<?php
2
+
3
+/*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+class Twig_Tests_Util_DeprecationCollectorTest extends PHPUnit_Framework_TestCase
13
+{
14
+    /**
15
+     * @requires PHP 5.3
16
+     */
17
+    public function testCollect()
18
+    {
19
+        $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
20
+        $twig->addFunction(new Twig_SimpleFunction('deprec', array($this, 'deprec'), array('deprecated' => true)));
21
+
22
+        $collector = new Twig_Util_DeprecationCollector($twig);
23
+        $deprecations = $collector->collect(new Twig_Tests_Util_Iterator());
24
+
25
+        $this->assertEquals(array('Twig Function "deprec" is deprecated in deprec.twig at line 1.'), $deprecations);
26
+    }
27
+
28
+    public function deprec()
29
+    {
30
+    }
31
+}
32
+
33
+class Twig_Tests_Util_Iterator implements IteratorAggregate
34
+{
35
+    public function getIterator()
36
+    {
37
+        return new ArrayIterator(array(
38
+            'ok.twig' => '{{ foo }}',
39
+            'deprec.twig' => '{{ deprec("foo") }}',
40
+        ));
41
+    }
42
+}