Skip to content

Commit d5822e0

Browse files
Merge branch '6.3' into 6.4
* 6.3: [FrameworkBundle] Fixed parsing new JSON output of debug:config not possible [DependencyInjection] Skip errored definitions deep-referenced as runtime exceptions [AssetMapper] Allow DirectoryResource for cache [PhpUnitBridge] Require PHPUnit 9.6 by default [WebProfilerBundle] Fix the accessibility of some background color [HttpKernel] Nullable and default value arguments in RequestPayloadValueResolver [WebProfilerBundle] right blocks: fix display [Messenger] Preserve existing Doctrine schema [Serializer] Refactor tests to not extends ObjectNormalizer [HttpFoundation] Make Request::getPayload() return an empty InputBag if request body is empty [HttpClient] Explicitly exclude CURLOPT_POSTREDIR [FrameworkBundle] Fix setting decorated services during tests
2 parents 4575794 + a95cbb3 commit d5822e0

File tree

7 files changed

+66
-70
lines changed

7 files changed

+66
-70
lines changed

Command/ConfigDebugCommand.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected function configure(): void
4949
new InputArgument('name', InputArgument::OPTIONAL, 'The bundle name or the extension alias'),
5050
new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),
5151
new InputOption('resolve-env', null, InputOption::VALUE_NONE, 'Display resolved environment variable values instead of placeholders'),
52-
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), class_exists(Yaml::class) ? 'yaml' : 'json'),
52+
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), class_exists(Yaml::class) ? 'txt' : 'json'),
5353
])
5454
->setHelp(<<<EOF
5555
The <info>%command.name%</info> command dumps the current configuration for an
@@ -97,16 +97,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9797

9898
$format = $input->getOption('format');
9999

100-
if ('yaml' === $format && !class_exists(Yaml::class)) {
101-
$errorIo->error('Setting the "format" option to "yaml" requires the Symfony Yaml component. Try running "composer install symfony/yaml" or use "--format=json" instead.');
100+
if (\in_array($format, ['txt', 'yml'], true) && !class_exists(Yaml::class)) {
101+
$errorIo->error('Setting the "format" option to "txt" or "yaml" requires the Symfony Yaml component. Try running "composer install symfony/yaml" or use "--format=json" instead.');
102102

103103
return 1;
104104
}
105105

106106
if (null === $path = $input->getArgument('path')) {
107-
$io->title(
108-
sprintf('Current configuration for %s', $name === $extensionAlias ? sprintf('extension with alias "%s"', $extensionAlias) : sprintf('"%s"', $name))
109-
);
107+
if ('txt' === $input->getOption('format')) {
108+
$io->title(
109+
sprintf('Current configuration for %s', $name === $extensionAlias ? sprintf('extension with alias "%s"', $extensionAlias) : sprintf('"%s"', $name))
110+
);
111+
}
110112

111113
$io->writeln($this->convertToFormat([$extensionAlias => $config], $format));
112114

@@ -131,7 +133,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
131133
private function convertToFormat(mixed $config, string $format): string
132134
{
133135
return match ($format) {
134-
'yaml' => Yaml::dump($config, 10),
136+
'txt', 'yaml' => Yaml::dump($config, 10),
135137
'json' => json_encode($config, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE),
136138
default => throw new InvalidArgumentException(sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
137139
};
@@ -268,6 +270,6 @@ private static function buildPathsCompletion(array $paths, string $prefix = ''):
268270

269271
private function getAvailableFormatOptions(): array
270272
{
271-
return ['yaml', 'json'];
273+
return ['txt', 'yaml', 'json'];
272274
}
273275
}

DependencyInjection/Compiler/TestServiceContainerRealRefPass.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public function process(ContainerBuilder $container)
4141
if ($id !== $target) {
4242
$renamedIds[$id] = $target;
4343
}
44+
if ($inner = $definitions[$target]->getTag('container.decorator')[0]['inner'] ?? null) {
45+
$renamedIds[$id] = $inner;
46+
}
4447
} else {
4548
unset($privateServices[$id]);
4649
}

Tests/Functional/Bundle/TestBundle/TestServiceContainer/PrivateService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313

1414
class PrivateService
1515
{
16+
public $inner;
1617
}

Tests/Functional/ConfigDebugCommandTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ public function testDumpBundleOption(bool $debug)
8484
$this->assertStringContainsString('foo', $tester->getDisplay());
8585
}
8686

87+
/**
88+
* @testWith [true]
89+
* [false]
90+
*/
91+
public function testDumpWithoutTitleIsValidJson(bool $debug)
92+
{
93+
$tester = $this->createCommandTester($debug);
94+
$ret = $tester->execute(['name' => 'TestBundle', '--format' => 'json']);
95+
96+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
97+
$this->assertJson($tester->getDisplay());
98+
}
99+
87100
/**
88101
* @testWith [true]
89102
* [false]
@@ -93,7 +106,7 @@ public function testDumpWithUnsupportedFormat(bool $debug)
93106
$tester = $this->createCommandTester($debug);
94107

95108
$this->expectException(InvalidArgumentException::class);
96-
$this->expectExceptionMessage('Supported formats are "yaml", "json"');
109+
$this->expectExceptionMessage('Supported formats are "txt", "yaml", "json"');
97110

98111
$tester->execute([
99112
'name' => 'test',

Tests/Functional/KernelTestCaseTest.php

Lines changed: 0 additions & 61 deletions
This file was deleted.

Tests/Functional/TestServiceContainerTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PrivateService;
1717
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PublicService;
1818
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\UnusedPrivateService;
19+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1920

2021
class TestServiceContainerTest extends AbstractWebTestCase
2122
{
@@ -40,6 +41,33 @@ public function testThatPrivateServicesAreAvailableIfTestConfigIsEnabled()
4041
$this->assertFalse(static::getContainer()->has(UnusedPrivateService::class));
4142
}
4243

44+
public function testThatPrivateServicesCanBeSetIfTestConfigIsEnabled()
45+
{
46+
static::bootKernel(['test_case' => 'TestServiceContainer']);
47+
48+
$container = static::getContainer();
49+
50+
$service = new \stdClass();
51+
52+
$container->set('private_service', $service);
53+
$this->assertSame($service, $container->get('private_service'));
54+
55+
$this->expectException(InvalidArgumentException::class);
56+
$this->expectExceptionMessage('The "private_service" service is already initialized, you cannot replace it.');
57+
$container->set('private_service', new \stdClass());
58+
}
59+
60+
public function testSetDecoratedService()
61+
{
62+
static::bootKernel(['test_case' => 'TestServiceContainer']);
63+
64+
$container = static::getContainer();
65+
66+
$service = new PrivateService();
67+
$container->set('decorated', $service);
68+
$this->assertSame($service, $container->get('decorated')->inner);
69+
}
70+
4371
/**
4472
* @doesNotPerformAssertions
4573
*/

Tests/Functional/app/TestServiceContainer/services.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@ services:
88

99
private_service: '@Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PrivateService'
1010

11+
decorated:
12+
class: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PrivateService
13+
1114
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PublicService:
1215
public: true
1316
arguments:
1417
- '@Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\NonPublicService'
1518
- '@Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PrivateService'
19+
- '@decorated'
20+
21+
decorator:
22+
class: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PrivateService
23+
decorates: decorated
24+
properties:
25+
inner: '@.inner'

0 commit comments

Comments
 (0)