ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
CustomExtensionTest.php
Go to the documentation of this file.
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 {
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 
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 }
Interface implemented by extension classes.
getFilters()
Returns a list of filters to add to the existing list.
getNodeVisitors()
Returns the node visitor instances to add to the existing list.
getGlobals()
Returns a list of global variables to add to the existing list.
$env
testGetInvalidOperators(Twig_ExtensionInterface $extension, $expectedExceptionMessage)
PHP 5.3 provideInvalidExtensions
getTokenParsers()
Returns the token parser instances to add to the existing list.
getTests()
Returns a list of tests to add to the existing list.
initRuntime(Twig_Environment $environment)
Initializes the runtime environment.
getOperators()
Returns a list of operators to add to the existing list.
Stores the Twig configuration.
Definition: Environment.php:17
getName()
Returns the name of the extension.
getFunctions()
Returns a list of functions to add to the existing list.