282df533 |
<?php
|
2119e60c |
namespace Twig\Tests;
|
e33020be |
/*
* 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.
*/
|
34bdab4d |
use PHPUnit\Framework\TestCase;
|
90d579e4 |
use Twig\Environment;
use Twig\Extension\ExtensionInterface;
use Twig\Loader\LoaderInterface;
|
34bdab4d |
class CustomExtensionTest extends TestCase
|
282df533 |
{
/**
* @dataProvider provideInvalidExtensions
*/
|
90d579e4 |
public function testGetInvalidOperators(ExtensionInterface $extension, $expectedExceptionMessage)
|
282df533 |
{
|
5ebcecf2 |
$this->expectException(\InvalidArgumentException::class);
|
b776e41f |
$this->expectExceptionMessage($expectedExceptionMessage);
|
282df533 |
|
656c295e |
$env = new Environment($this->createMock(LoaderInterface::class));
|
282df533 |
$env->addExtension($extension);
|
e33020be |
$env->getUnaryOperators();
|
282df533 |
}
public function provideInvalidExtensions()
{
|
5c55243d |
return [
|
2119e60c |
[new InvalidOperatorExtension([1, 2, 3]), '"Twig\Tests\InvalidOperatorExtension::getOperators()" must return an array of 2 elements, got 3.'],
|
5c55243d |
];
|
282df533 |
}
}
|
90d579e4 |
class InvalidOperatorExtension implements ExtensionInterface
|
282df533 |
{
private $operators;
public function __construct($operators)
{
$this->operators = $operators;
}
|
54cec4e3 |
public function getTokenParsers(): array
|
282df533 |
{
|
5c55243d |
return [];
|
282df533 |
}
|
54cec4e3 |
public function getNodeVisitors(): array
|
282df533 |
{
|
5c55243d |
return [];
|
282df533 |
}
|
54cec4e3 |
public function getFilters(): array
|
282df533 |
{
|
5c55243d |
return [];
|
282df533 |
}
|
54cec4e3 |
public function getTests(): array
|
282df533 |
{
|
5c55243d |
return [];
|
282df533 |
}
|
54cec4e3 |
public function getFunctions(): array
|
282df533 |
{
|
5c55243d |
return [];
|
282df533 |
}
|
54cec4e3 |
public function getOperators(): array
|
282df533 |
{
return $this->operators;
}
}
|