Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef54646

Browse files
minor #54810 [TwigBundle] Fix deprecation warnings about base_template_class (derrabus)
This PR was merged into the 7.1 branch. Discussion ---------- [TwigBundle] Fix deprecation warnings about base_template_class | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Follows #54657 | License | MIT Since #54657, TwigBundle uses its own deprecated option in non-legacy tests. This PR fixes this by testing that option and the triggered deprecation message in a separate test. Commits ------- 10d48cd [TwigBundle] Fix deprecation warnings about base_template_class
2 parents e19cb80 + 10d48cd commit ef54646

File tree

8 files changed

+52
-15
lines changed

8 files changed

+52
-15
lines changed

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
'bad' => ['key' => 'foo'],
1212
],
1313
'auto_reload' => true,
14-
'base_template_class' => 'stdClass',
1514
'cache' => '/tmp',
1615
'charset' => 'ISO-8859-1',
1716
'debug' => true,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
$container->loadFromExtension('twig', [
4+
'base_template_class' => 'stdClass',
5+
]);

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/extra.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
77
http://symfony.com/schema/dic/twig https://symfony.com/schema/dic/twig/twig-1.0.xsd">
88

9-
<twig:config auto-reload="true" base-template-class="stdClass" cache="/tmp" charset="ISO-8859-1" debug="true" strict-variables="true">
9+
<twig:config auto-reload="true" cache="/tmp" charset="ISO-8859-1" debug="true" strict-variables="true">
1010
<twig:path namespace="namespace3">namespaced_path3</twig:path>
1111
</twig:config>
1212
</container>

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
77
http://symfony.com/schema/dic/twig https://symfony.com/schema/dic/twig/twig-1.0.xsd">
88

9-
<twig:config auto-reload="true" base-template-class="stdClass" cache="/tmp" charset="ISO-8859-1" debug="true" strict-variables="true" default-path="%kernel.project_dir%/Fixtures/templates">
9+
<twig:config auto-reload="true" cache="/tmp" charset="ISO-8859-1" debug="true" strict-variables="true" default-path="%kernel.project_dir%/Fixtures/templates">
1010
<twig:form-theme>MyBundle::form.html.twig</twig:form-theme>
1111
<twig:global key="foo" id="bar" type="service" />
1212
<twig:global key="baz">@@qux</twig:global>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:twig="http://symfony.com/schema/dic/twig"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/twig https://symfony.com/schema/dic/twig/twig-1.0.xsd">
8+
9+
<twig:config base-template-class="stdClass" />
10+
</container>

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ twig:
77
pi: 3.14
88
bad: {key: foo}
99
auto_reload: true
10-
base_template_class: stdClass
1110
cache: /tmp
1211
charset: ISO-8859-1
1312
debug: true
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
twig:
2+
base_template_class: stdClass

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection;
1313

14+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1415
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\RuntimeLoaderPass;
1516
use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension;
1617
use Symfony\Bundle\TwigBundle\Tests\DependencyInjection\AcmeBundle\AcmeBundle;
@@ -31,6 +32,8 @@
3132

3233
class TwigExtensionTest extends TestCase
3334
{
35+
use ExpectDeprecationTrait;
36+
3437
public function testLoadEmptyConfiguration()
3538
{
3639
$container = $this->createContainer();
@@ -56,7 +59,7 @@ public function testLoadEmptyConfiguration()
5659
/**
5760
* @dataProvider getFormats
5861
*/
59-
public function testLoadFullConfiguration($format)
62+
public function testLoadFullConfiguration(string $format)
6063
{
6164
$container = $this->createContainer();
6265
$container->registerExtension(new TwigExtension());
@@ -91,17 +94,36 @@ public function testLoadFullConfiguration($format)
9194
$options = $container->getDefinition('twig')->getArgument(1);
9295
$this->assertTrue($options['auto_reload'], '->load() sets the auto_reload option');
9396
$this->assertSame('name', $options['autoescape'], '->load() sets the autoescape option');
94-
$this->assertEquals('stdClass', $options['base_template_class'], '->load() sets the base_template_class option');
97+
$this->assertArrayNotHasKey('base_template_class', $options, '->load() does not set the base_template_class if none is provided');
9598
$this->assertEquals('/tmp', $options['cache'], '->load() sets the cache option');
9699
$this->assertEquals('ISO-8859-1', $options['charset'], '->load() sets the charset option');
97100
$this->assertTrue($options['debug'], '->load() sets the debug option');
98101
$this->assertTrue($options['strict_variables'], '->load() sets the strict_variables option');
99102
}
100103

104+
/**
105+
* @group legacy
106+
*
107+
* @dataProvider getFormats
108+
*/
109+
public function testLoadCustomBaseTemplateClassConfiguration(string $format)
110+
{
111+
$container = $this->createContainer();
112+
$container->registerExtension(new TwigExtension());
113+
114+
$this->expectDeprecation('Since symfony/twig-bundle 7.1: The child node "base_template_class" at path "twig" is deprecated.');
115+
116+
$this->loadFromFile($container, 'templateClass', $format);
117+
$this->compileContainer($container);
118+
119+
$options = $container->getDefinition('twig')->getArgument(1);
120+
$this->assertEquals('stdClass', $options['base_template_class'], '->load() sets the base_template_class option');
121+
}
122+
101123
/**
102124
* @dataProvider getFormats
103125
*/
104-
public function testLoadCustomTemplateEscapingGuesserConfiguration($format)
126+
public function testLoadCustomTemplateEscapingGuesserConfiguration(string $format)
105127
{
106128
$container = $this->createContainer();
107129
$container->registerExtension(new TwigExtension());
@@ -115,7 +137,7 @@ public function testLoadCustomTemplateEscapingGuesserConfiguration($format)
115137
/**
116138
* @dataProvider getFormats
117139
*/
118-
public function testLoadDefaultTemplateEscapingGuesserConfiguration($format)
140+
public function testLoadDefaultTemplateEscapingGuesserConfiguration(string $format)
119141
{
120142
$container = $this->createContainer();
121143
$container->registerExtension(new TwigExtension());
@@ -129,7 +151,7 @@ public function testLoadDefaultTemplateEscapingGuesserConfiguration($format)
129151
/**
130152
* @dataProvider getFormats
131153
*/
132-
public function testLoadCustomDateFormats($fileFormat)
154+
public function testLoadCustomDateFormats(string $fileFormat)
133155
{
134156
$container = $this->createContainer();
135157
$container->registerExtension(new TwigExtension());
@@ -178,7 +200,7 @@ public function testGlobalsWithDifferentTypesAndValues()
178200
/**
179201
* @dataProvider getFormats
180202
*/
181-
public function testTwigLoaderPaths($format)
203+
public function testTwigLoaderPaths(string $format)
182204
{
183205
$container = $this->createContainer();
184206
$container->registerExtension(new TwigExtension());
@@ -207,7 +229,7 @@ public function testTwigLoaderPaths($format)
207229
], $paths);
208230
}
209231

210-
public static function getFormats()
232+
public static function getFormats(): array
211233
{
212234
return [
213235
['php'],
@@ -219,7 +241,7 @@ public static function getFormats()
219241
/**
220242
* @dataProvider stopwatchExtensionAvailabilityProvider
221243
*/
222-
public function testStopwatchExtensionAvailability($debug, $stopwatchEnabled, $expected)
244+
public function testStopwatchExtensionAvailability(bool $debug, bool $stopwatchEnabled, bool $expected)
223245
{
224246
$container = $this->createContainer();
225247
$container->setParameter('kernel.debug', $debug);
@@ -290,7 +312,7 @@ public function testCustomHtmlToTextConverterService(string $format)
290312
$this->assertEquals(new Reference('my_converter'), $bodyRenderer->getArgument('$converter'));
291313
}
292314

293-
private function createContainer()
315+
private function createContainer(): ContainerBuilder
294316
{
295317
$container = new ContainerBuilder(new ParameterBag([
296318
'kernel.cache_dir' => __DIR__,
@@ -311,15 +333,15 @@ private function createContainer()
311333
return $container;
312334
}
313335

314-
private function compileContainer(ContainerBuilder $container)
336+
private function compileContainer(ContainerBuilder $container): void
315337
{
316338
$container->getCompilerPassConfig()->setOptimizationPasses([]);
317339
$container->getCompilerPassConfig()->setRemovingPasses([]);
318340
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);
319341
$container->compile();
320342
}
321343

322-
private function loadFromFile(ContainerBuilder $container, $file, $format)
344+
private function loadFromFile(ContainerBuilder $container, string $file, string $format): void
323345
{
324346
$locator = new FileLocator(__DIR__.'/Fixtures/'.$format);
325347

0 commit comments

Comments
 (0)