Skip to content

Commit ba2b633

Browse files
Merge branch '5.3' into 5.4
* 5.3: Fix skip condition for INTL [Messenger] Fix `ErrorDetailsStamp` denormalization [Translation] Extract translatable content on twig set Simplify code Fix composer.json versions Fix composer.json versions Remove redundant license info [HttpFoundation] Fix isNotModified determination logic Fix Url Validator false positives [Translation] Reverse fallback locales [FrameworkBundle] Fall back to default configuration in debug:config and consistently resolve parameter values notifier smsapi - fixed checking whether message is sent allow null for framework.translator.default_path improve failure messages of the CrawlerSelectorTextContains constraint
2 parents 8bded8a + 8865bac commit ba2b633

File tree

12 files changed

+170
-18
lines changed

12 files changed

+170
-18
lines changed

Command/ConfigDebugCommand.php

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

1414
use Symfony\Component\Config\Definition\ConfigurationInterface;
15+
use Symfony\Component\Config\Definition\Processor;
1516
use Symfony\Component\Console\Exception\LogicException;
1617
use Symfony\Component\Console\Input\InputArgument;
1718
use Symfony\Component\Console\Input\InputInterface;
@@ -90,22 +91,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9091
}
9192

9293
$extension = $this->findExtension($name);
93-
$container = $this->compileContainer();
94-
9594
$extensionAlias = $extension->getAlias();
96-
$extensionConfig = [];
97-
foreach ($container->getCompilerPassConfig()->getPasses() as $pass) {
98-
if ($pass instanceof ValidateEnvPlaceholdersPass) {
99-
$extensionConfig = $pass->getExtensionConfig();
100-
break;
101-
}
102-
}
103-
104-
if (!isset($extensionConfig[$extensionAlias])) {
105-
throw new \LogicException(sprintf('The extension with alias "%s" does not have configuration.', $extensionAlias));
106-
}
95+
$container = $this->compileContainer();
10796

108-
$config = $container->resolveEnvPlaceholders($extensionConfig[$extensionAlias]);
97+
$config = $container->resolveEnvPlaceholders(
98+
$container->getParameterBag()->resolveValue(
99+
$this->getConfigForExtension($extension, $container)
100+
)
101+
);
109102

110103
if (null === $path = $input->getArgument('path')) {
111104
$io->title(
@@ -166,4 +159,33 @@ private function getConfigForPath(array $config, string $path, string $alias)
166159

167160
return $config;
168161
}
162+
163+
private function getConfigForExtension(ExtensionInterface $extension, ContainerBuilder $container): array
164+
{
165+
$extensionAlias = $extension->getAlias();
166+
167+
$extensionConfig = [];
168+
foreach ($container->getCompilerPassConfig()->getPasses() as $pass) {
169+
if ($pass instanceof ValidateEnvPlaceholdersPass) {
170+
$extensionConfig = $pass->getExtensionConfig();
171+
break;
172+
}
173+
}
174+
175+
if (isset($extensionConfig[$extensionAlias])) {
176+
return $extensionConfig[$extensionAlias];
177+
}
178+
179+
// Fall back to default config if the extension has one
180+
181+
if (!$extension instanceof ConfigurationExtensionInterface) {
182+
throw new \LogicException(sprintf('The extension with alias "%s" does not have configuration.', $extensionAlias));
183+
}
184+
185+
$configs = $container->getExtensionConfig($extensionAlias);
186+
$configuration = $extension->getConfiguration($configs, $container);
187+
$this->validateConfiguration($extension, $configuration);
188+
189+
return (new Processor())->processConfiguration($configuration, $configs);
190+
}
169191
}

DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,9 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
12861286
$container->getDefinition('console.command.translation_update')->replaceArgument(6, $transPaths);
12871287
}
12881288

1289-
if ($container->fileExists($defaultDir)) {
1289+
if (null === $defaultDir) {
1290+
// allow null
1291+
} elseif ($container->fileExists($defaultDir)) {
12901292
$dirs[] = $defaultDir;
12911293
} else {
12921294
$nonExistingDirs[] = $defaultDir;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\DefaultConfigTestBundle;
4+
5+
use Symfony\Component\HttpKernel\Bundle\Bundle;
6+
7+
class DefaultConfigTestBundle extends Bundle
8+
{
9+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\DefaultConfigTestBundle\DependencyInjection;
4+
5+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6+
use Symfony\Component\Config\Definition\ConfigurationInterface;
7+
8+
class Configuration implements ConfigurationInterface
9+
{
10+
public function getConfigTreeBuilder(): TreeBuilder
11+
{
12+
$treeBuilder = new TreeBuilder('default_config_test');
13+
14+
$treeBuilder->getRootNode()
15+
->children()
16+
->scalarNode('foo')->defaultValue('%default_config_test_foo%')->end()
17+
->scalarNode('baz')->defaultValue('%env(BAZ)%')->end()
18+
->end();
19+
20+
return $treeBuilder;
21+
}
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\DefaultConfigTestBundle\DependencyInjection;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\DependencyInjection\Extension\Extension;
7+
8+
class DefaultConfigTestExtension extends Extension
9+
{
10+
public function load(array $configs, ContainerBuilder $container)
11+
{
12+
$configuration = new Configuration();
13+
$config = $this->processConfiguration($configuration, $configs);
14+
15+
$container->setParameter('default_config_test', $config['foo']);
16+
$container->setParameter('default_config_test', $config['baz']);
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\ExtensionWithoutConfigTestBundle\DependencyInjection;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
7+
8+
class ExtensionWithoutConfigTestExtension implements ExtensionInterface
9+
{
10+
public function load(array $configs, ContainerBuilder $container)
11+
{
12+
}
13+
14+
public function getNamespace()
15+
{
16+
return '';
17+
}
18+
19+
public function getXsdValidationBasePath()
20+
{
21+
return false;
22+
}
23+
24+
public function getAlias()
25+
{
26+
return 'extension_without_config_test';
27+
}
28+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\ExtensionWithoutConfigTestBundle;
4+
5+
use Symfony\Component\HttpKernel\Bundle\Bundle;
6+
7+
class ExtensionWithoutConfigTestBundle extends Bundle
8+
{
9+
}

Tests/Functional/ConfigDebugCommandTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ public function testParametersValuesAreResolved()
5858
$this->assertStringContainsString('secret: test', $tester->getDisplay());
5959
}
6060

61+
public function testDefaultParameterValueIsResolvedIfConfigIsExisting()
62+
{
63+
$tester = $this->createCommandTester();
64+
$ret = $tester->execute(['name' => 'framework']);
65+
66+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
67+
$kernelCacheDir = $this->application->getKernel()->getContainer()->getParameter('kernel.cache_dir');
68+
$this->assertStringContainsString(sprintf("dsn: 'file:%s/profiler'", $kernelCacheDir), $tester->getDisplay());
69+
}
70+
6171
public function testDumpUndefinedBundleOption()
6272
{
6373
$tester = $this->createCommandTester();
@@ -74,6 +84,33 @@ public function testDumpWithPrefixedEnv()
7484
$this->assertStringContainsString("cookie_httponly: '%env(bool:COOKIE_HTTPONLY)%'", $tester->getDisplay());
7585
}
7686

87+
public function testDumpFallsBackToDefaultConfigAndResolvesParameterValue()
88+
{
89+
$tester = $this->createCommandTester();
90+
$ret = $tester->execute(['name' => 'DefaultConfigTestBundle']);
91+
92+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
93+
$this->assertStringContainsString('foo: bar', $tester->getDisplay());
94+
}
95+
96+
public function testDumpFallsBackToDefaultConfigAndResolvesEnvPlaceholder()
97+
{
98+
$tester = $this->createCommandTester();
99+
$ret = $tester->execute(['name' => 'DefaultConfigTestBundle']);
100+
101+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
102+
$this->assertStringContainsString("baz: '%env(BAZ)%'", $tester->getDisplay());
103+
}
104+
105+
public function testDumpThrowsExceptionWhenDefaultConfigFallbackIsImpossible()
106+
{
107+
$this->expectException(\LogicException::class);
108+
$this->expectExceptionMessage('The extension with alias "extension_without_config_test" does not have configuration.');
109+
110+
$tester = $this->createCommandTester();
111+
$tester->execute(['name' => 'ExtensionWithoutConfigTestBundle']);
112+
}
113+
77114
private function createCommandTester(): CommandTester
78115
{
79116
$command = $this->application->find('debug:config');

Tests/Functional/app/ConfigDump/bundles.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
*/
1111

1212
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
13+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\DefaultConfigTestBundle\DefaultConfigTestBundle;
14+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\ExtensionWithoutConfigTestBundle\ExtensionWithoutConfigTestBundle;
1315
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
1416

1517
return [
18+
new DefaultConfigTestBundle(),
19+
new ExtensionWithoutConfigTestBundle(),
1620
new FrameworkBundle(),
1721
new TestBundle(),
1822
];

Tests/Functional/app/ConfigDump/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ parameters:
1212
env(LOCALE): en
1313
env(COOKIE_HTTPONLY): '1'
1414
secret: test
15+
default_config_test_foo: bar

Tests/Test/WebTestCaseTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public function testAssertSelectorTextNotContains()
199199
{
200200
$this->getCrawlerTester(new Crawler('<html><body><h1>Foo'))->assertSelectorTextNotContains('body > h1', 'Bar');
201201
$this->expectException(AssertionFailedError::class);
202-
$this->expectExceptionMessage('matches selector "body > h1" and does not have a node matching selector "body > h1" with content containing "Foo".');
202+
$this->expectExceptionMessage('matches selector "body > h1" and the text "Foo" of the node matching selector "body > h1" does not contain "Foo".');
203203
$this->getCrawlerTester(new Crawler('<html><body><h1>Foo'))->assertSelectorTextNotContains('body > h1', 'Foo');
204204
}
205205

@@ -215,7 +215,7 @@ public function testAssertPageTitleContains()
215215
{
216216
$this->getCrawlerTester(new Crawler('<html><head><title>Foobar'))->assertPageTitleContains('Foo');
217217
$this->expectException(AssertionFailedError::class);
218-
$this->expectExceptionMessage('matches selector "title" and has a node matching selector "title" with content containing "Bar".');
218+
$this->expectExceptionMessage('matches selector "title" and the text "Foo" of the node matching selector "title" contains "Bar".');
219219
$this->getCrawlerTester(new Crawler('<html><head><title>Foo'))->assertPageTitleContains('Bar');
220220
}
221221

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"symfony/browser-kit": "^5.4|^6.0",
4141
"symfony/console": "^5.4|^6.0",
4242
"symfony/css-selector": "^4.4|^5.0|^6.0",
43-
"symfony/dom-crawler": "^4.4|^5.0|^6.0",
43+
"symfony/dom-crawler": "^4.4.30|^5.3.7|^6.0",
4444
"symfony/dotenv": "^5.1|^6.0",
4545
"symfony/polyfill-intl-icu": "~1.0",
4646
"symfony/form": "^5.2|^6.0",

0 commit comments

Comments
 (0)