diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php index 9e7b500795ec6..f87af5a1baba4 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -11,7 +11,6 @@ 'bad' => ['key' => 'foo'], ], 'auto_reload' => true, - 'base_template_class' => 'stdClass', 'cache' => '/tmp', 'charset' => 'ISO-8859-1', 'debug' => true, diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/templateClass.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/templateClass.php new file mode 100644 index 0000000000000..bf995046314fa --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/templateClass.php @@ -0,0 +1,5 @@ +loadFromExtension('twig', [ + 'base_template_class' => 'stdClass', +]); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/extra.xml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/extra.xml index 92767e411057f..f1cf8985329d0 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/extra.xml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/extra.xml @@ -6,7 +6,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/twig https://symfony.com/schema/dic/twig/twig-1.0.xsd"> - + namespaced_path3 diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index 3f7d1de266ec5..528a466b0452c 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -6,7 +6,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/twig https://symfony.com/schema/dic/twig/twig-1.0.xsd"> - + MyBundle::form.html.twig @@qux diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/templateClass.xml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/templateClass.xml new file mode 100644 index 0000000000000..a735ed8da258e --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/templateClass.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index d186724539927..6c249d378ff22 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -7,7 +7,6 @@ twig: pi: 3.14 bad: {key: foo} auto_reload: true - base_template_class: stdClass cache: /tmp charset: ISO-8859-1 debug: true diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/templateClass.yml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/templateClass.yml new file mode 100644 index 0000000000000..886a5ee60d9a5 --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/templateClass.yml @@ -0,0 +1,2 @@ +twig: + base_template_class: stdClass diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index 7a874e7bab8bc..bc7013c3cb70a 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\RuntimeLoaderPass; use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension; use Symfony\Bundle\TwigBundle\Tests\DependencyInjection\AcmeBundle\AcmeBundle; @@ -31,6 +32,8 @@ class TwigExtensionTest extends TestCase { + use ExpectDeprecationTrait; + public function testLoadEmptyConfiguration() { $container = $this->createContainer(); @@ -56,7 +59,7 @@ public function testLoadEmptyConfiguration() /** * @dataProvider getFormats */ - public function testLoadFullConfiguration($format) + public function testLoadFullConfiguration(string $format) { $container = $this->createContainer(); $container->registerExtension(new TwigExtension()); @@ -91,17 +94,36 @@ public function testLoadFullConfiguration($format) $options = $container->getDefinition('twig')->getArgument(1); $this->assertTrue($options['auto_reload'], '->load() sets the auto_reload option'); $this->assertSame('name', $options['autoescape'], '->load() sets the autoescape option'); - $this->assertEquals('stdClass', $options['base_template_class'], '->load() sets the base_template_class option'); + $this->assertArrayNotHasKey('base_template_class', $options, '->load() does not set the base_template_class if none is provided'); $this->assertEquals('/tmp', $options['cache'], '->load() sets the cache option'); $this->assertEquals('ISO-8859-1', $options['charset'], '->load() sets the charset option'); $this->assertTrue($options['debug'], '->load() sets the debug option'); $this->assertTrue($options['strict_variables'], '->load() sets the strict_variables option'); } + /** + * @group legacy + * + * @dataProvider getFormats + */ + public function testLoadCustomBaseTemplateClassConfiguration(string $format) + { + $container = $this->createContainer(); + $container->registerExtension(new TwigExtension()); + + $this->expectDeprecation('Since symfony/twig-bundle 7.1: The child node "base_template_class" at path "twig" is deprecated.'); + + $this->loadFromFile($container, 'templateClass', $format); + $this->compileContainer($container); + + $options = $container->getDefinition('twig')->getArgument(1); + $this->assertEquals('stdClass', $options['base_template_class'], '->load() sets the base_template_class option'); + } + /** * @dataProvider getFormats */ - public function testLoadCustomTemplateEscapingGuesserConfiguration($format) + public function testLoadCustomTemplateEscapingGuesserConfiguration(string $format) { $container = $this->createContainer(); $container->registerExtension(new TwigExtension()); @@ -115,7 +137,7 @@ public function testLoadCustomTemplateEscapingGuesserConfiguration($format) /** * @dataProvider getFormats */ - public function testLoadDefaultTemplateEscapingGuesserConfiguration($format) + public function testLoadDefaultTemplateEscapingGuesserConfiguration(string $format) { $container = $this->createContainer(); $container->registerExtension(new TwigExtension()); @@ -129,7 +151,7 @@ public function testLoadDefaultTemplateEscapingGuesserConfiguration($format) /** * @dataProvider getFormats */ - public function testLoadCustomDateFormats($fileFormat) + public function testLoadCustomDateFormats(string $fileFormat) { $container = $this->createContainer(); $container->registerExtension(new TwigExtension()); @@ -178,7 +200,7 @@ public function testGlobalsWithDifferentTypesAndValues() /** * @dataProvider getFormats */ - public function testTwigLoaderPaths($format) + public function testTwigLoaderPaths(string $format) { $container = $this->createContainer(); $container->registerExtension(new TwigExtension()); @@ -207,7 +229,7 @@ public function testTwigLoaderPaths($format) ], $paths); } - public static function getFormats() + public static function getFormats(): array { return [ ['php'], @@ -219,7 +241,7 @@ public static function getFormats() /** * @dataProvider stopwatchExtensionAvailabilityProvider */ - public function testStopwatchExtensionAvailability($debug, $stopwatchEnabled, $expected) + public function testStopwatchExtensionAvailability(bool $debug, bool $stopwatchEnabled, bool $expected) { $container = $this->createContainer(); $container->setParameter('kernel.debug', $debug); @@ -290,7 +312,7 @@ public function testCustomHtmlToTextConverterService(string $format) $this->assertEquals(new Reference('my_converter'), $bodyRenderer->getArgument('$converter')); } - private function createContainer() + private function createContainer(): ContainerBuilder { $container = new ContainerBuilder(new ParameterBag([ 'kernel.cache_dir' => __DIR__, @@ -311,7 +333,7 @@ private function createContainer() return $container; } - private function compileContainer(ContainerBuilder $container) + private function compileContainer(ContainerBuilder $container): void { $container->getCompilerPassConfig()->setOptimizationPasses([]); $container->getCompilerPassConfig()->setRemovingPasses([]); @@ -319,7 +341,7 @@ private function compileContainer(ContainerBuilder $container) $container->compile(); } - private function loadFromFile(ContainerBuilder $container, $file, $format) + private function loadFromFile(ContainerBuilder $container, string $file, string $format): void { $locator = new FileLocator(__DIR__.'/Fixtures/'.$format);