c706df264fed8bcf4142bd7b112c2b64a9ae37cf
[yaffs-website] / vendor / twig / twig / test / Twig / Tests / CustomExtensionTest.php
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 CustomExtensionTest extends PHPUnit_Framework_TestCase
13 {
14     /**
15      * @requires PHP 5.3
16      * @dataProvider provideInvalidExtensions
17      */
18     public function testGetInvalidOperators(Twig_ExtensionInterface $extension, $expectedExceptionMessage)
19     {
20         if (method_exists($this, 'expectException')) {
21             $this->expectException('InvalidArgumentException');
22             $this->expectExceptionMessage($expectedExceptionMessage);
23         } else {
24             $this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage);
25         }
26
27         $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
28         $env->addExtension($extension);
29         $env->getUnaryOperators();
30     }
31
32     public function provideInvalidExtensions()
33     {
34         return array(
35             array(new InvalidOperatorExtension(new stdClass()), '"InvalidOperatorExtension::getOperators()" must return an array with operators, got "stdClass".'),
36             array(new InvalidOperatorExtension(array(1, 2, 3)), '"InvalidOperatorExtension::getOperators()" must return an array of 2 elements, got 3.'),
37         );
38     }
39 }
40
41 class InvalidOperatorExtension implements Twig_ExtensionInterface
42 {
43     private $operators;
44
45     public function __construct($operators)
46     {
47         $this->operators = $operators;
48     }
49
50     public function initRuntime(Twig_Environment $environment)
51     {
52     }
53
54     public function getTokenParsers()
55     {
56         return array();
57     }
58
59     public function getNodeVisitors()
60     {
61         return array();
62     }
63
64     public function getFilters()
65     {
66         return array();
67     }
68
69     public function getTests()
70     {
71         return array();
72     }
73
74     public function getFunctions()
75     {
76         return array();
77     }
78
79     public function getGlobals()
80     {
81         return array();
82     }
83
84     public function getOperators()
85     {
86         return $this->operators;
87     }
88
89     public function getName()
90     {
91         return __CLASS__;
92     }
93 }