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
12use Twig\Environment;
13use Twig\TwigFunction;
14use Twig\Util\DeprecationCollector;
15
16class Twig_Tests_Util_DeprecationCollectorTest extends \PHPUnit\Framework\TestCase
17{
18    /**
19     * @requires PHP 5.3
20     */
21    public function testCollect()
22    {
23        $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
24        $twig->addFunction(new TwigFunction('deprec', [$this, 'deprec'], ['deprecated' => true]));
25
26        $collector = new DeprecationCollector($twig);
27        $deprecations = $collector->collect(new Twig_Tests_Util_Iterator());
28
29        $this->assertEquals(['Twig Function "deprec" is deprecated in deprec.twig at line 1.'], $deprecations);
30    }
31
32    public function deprec()
33    {
34    }
35}
36
37class Twig_Tests_Util_Iterator implements \IteratorAggregate
38{
39    public function getIterator()
40    {
41        return new \ArrayIterator([
42            'ok.twig' => '{{ foo }}',
43            'deprec.twig' => '{{ deprec("foo") }}',
44        ]);
45    }
46}
47