This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection\Compiler;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExtensionPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
class ExtensionPassTest extends TestCase
{
public function testProcessDoesNotDropExistingFileLoaderMethodCalls()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.root_dir', __DIR__);
$container->register('twig.app_variable', '\Symfony\Bridge\Twig\AppVariable');
$container->register('templating', '\Symfony\Bundle\TwigBundle\TwigEngine');
$container->register('twig.extension.yaml');
$container->register('twig.extension.debug.stopwatch');
$container->register('twig.extension.expression');
$nativeTwigLoader = new Definition('\Twig\Loader\FilesystemLoader');
$nativeTwigLoader->addMethodCall('addPath', array());
$container->setDefinition('twig.loader.native_filesystem', $nativeTwigLoader);
$filesystemLoader = new Definition('\Symfony\Bundle\TwigBundle\Loader\FilesystemLoader');
$filesystemLoader->setArguments(array(null, null, null));
$filesystemLoader->addMethodCall('addPath', array());
$container->setDefinition('twig.loader.filesystem', $filesystemLoader);
$extensionPass = new ExtensionPass();
$extensionPass->process($container);
$this->assertCount(2, $filesystemLoader->getMethodCalls());
}
}

View File

@@ -0,0 +1,151 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection\Compiler;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigLoaderPass;
class TwigLoaderPassTest extends TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $builder;
/**
* @var Definition
*/
private $chainLoader;
/**
* @var TwigLoaderPass
*/
private $pass;
protected function setUp()
{
$this->builder = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'setAlias', 'getDefinition'))->getMock();
$this->chainLoader = new Definition('loader');
$this->pass = new TwigLoaderPass();
}
public function testMapperPassWithOneTaggedLoaders()
{
$serviceIds = array(
'test_loader_1' => array(
array(),
),
);
$this->builder->expects($this->once())
->method('hasDefinition')
->with('twig')
->will($this->returnValue(true));
$this->builder->expects($this->once())
->method('findTaggedServiceIds')
->with('twig.loader')
->will($this->returnValue($serviceIds));
$this->builder->expects($this->once())
->method('setAlias')
->with('twig.loader', 'test_loader_1');
$this->pass->process($this->builder);
}
public function testMapperPassWithTwoTaggedLoaders()
{
$serviceIds = array(
'test_loader_1' => array(
array(),
),
'test_loader_2' => array(
array(),
),
);
$this->builder->expects($this->once())
->method('hasDefinition')
->with('twig')
->will($this->returnValue(true));
$this->builder->expects($this->once())
->method('findTaggedServiceIds')
->with('twig.loader')
->will($this->returnValue($serviceIds));
$this->builder->expects($this->once())
->method('getDefinition')
->with('twig.loader.chain')
->will($this->returnValue($this->chainLoader));
$this->builder->expects($this->once())
->method('setAlias')
->with('twig.loader', 'twig.loader.chain');
$this->pass->process($this->builder);
$calls = $this->chainLoader->getMethodCalls();
$this->assertCount(2, $calls);
$this->assertEquals('addLoader', $calls[0][0]);
$this->assertEquals('addLoader', $calls[1][0]);
$this->assertEquals('test_loader_1', (string) $calls[0][1][0]);
$this->assertEquals('test_loader_2', (string) $calls[1][1][0]);
}
public function testMapperPassWithTwoTaggedLoadersWithPriority()
{
$serviceIds = array(
'test_loader_1' => array(
array('priority' => 100),
),
'test_loader_2' => array(
array('priority' => 200),
),
);
$this->builder->expects($this->once())
->method('hasDefinition')
->with('twig')
->will($this->returnValue(true));
$this->builder->expects($this->once())
->method('findTaggedServiceIds')
->with('twig.loader')
->will($this->returnValue($serviceIds));
$this->builder->expects($this->once())
->method('getDefinition')
->with('twig.loader.chain')
->will($this->returnValue($this->chainLoader));
$this->builder->expects($this->once())
->method('setAlias')
->with('twig.loader', 'twig.loader.chain');
$this->pass->process($this->builder);
$calls = $this->chainLoader->getMethodCalls();
$this->assertCount(2, $calls);
$this->assertEquals('addLoader', $calls[0][0]);
$this->assertEquals('addLoader', $calls[1][0]);
$this->assertEquals('test_loader_2', (string) $calls[0][1][0]);
$this->assertEquals('test_loader_1', (string) $calls[1][1][0]);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
*/
public function testMapperPassWithZeroTaggedLoaders()
{
$this->builder->expects($this->once())
->method('hasDefinition')
->with('twig')
->will($this->returnValue(true));
$this->builder->expects($this->once())
->method('findTaggedServiceIds')
->with('twig.loader')
->will($this->returnValue(array()));
$this->pass->process($this->builder);
}
}