simplified a test

This commit is contained in:
Fabien Potencier
2016-12-13 11:21:33 +01:00
parent 0e0c534252
commit e33020becf
+15 -13
View File
@@ -1,37 +1,39 @@
<?php
final class CustomExtensionTest extends \PHPUnit_Framework_TestCase
/*
* 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 CustomExtensionTest extends PHPUnit_Framework_TestCase
{
/**
* @param Twig_ExtensionInterface $extension
* @param string $expectedExceptionMessage
*
* @requires PHP 5.3
* @dataProvider provideInvalidExtensions
*/
public function testGetInvalidOperators(\Twig_ExtensionInterface $extension, $expectedExceptionMessage)
public function testGetInvalidOperators(Twig_ExtensionInterface $extension, $expectedExceptionMessage)
{
$this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage);
$loader = new \Twig_Loader_Array(array('foo' => '{{ foo }}'));
$env = new \Twig_Environment($loader);
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
$env->addExtension($extension);
$method = new \ReflectionMethod($env, 'initExtensions');
$method->setAccessible(true);
$method->invoke($env);
$env->getUnaryOperators();
}
public function provideInvalidExtensions()
{
return array(
array(new InvalidOperatorExtension(new \stdClass()), '"InvalidOperatorExtension::getOperators()" must return an array with operators, got "stdClass".'),
array(new InvalidOperatorExtension(new stdClass()), '"InvalidOperatorExtension::getOperators()" must return an array with operators, got "stdClass".'),
array(new InvalidOperatorExtension(array(1, 2, 3)), '"InvalidOperatorExtension::getOperators()" must return an array of 2 elements, got 3.'),
);
}
}
final class InvalidOperatorExtension implements \Twig_ExtensionInterface
class InvalidOperatorExtension implements Twig_ExtensionInterface
{
private $operators;