Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 022653f

Browse filesBrowse files
noemi-salaunNoémi Salaün
authored and
Noémi Salaün
committed
[FrameworkBundle] add all formats support for debug:container --deprecations command
1 parent c587b85 commit 022653f
Copy full SHA for 022653f

19 files changed

+170
-32
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ CHANGELOG
1313
* The `TemplateController` now accepts context argument
1414
* Deprecated *not* setting the "framework.router.utf8" configuration option as it will default to `true` in Symfony 6.0
1515
* Added tag `routing.expression_language_function` to define functions available in route conditions
16-
* Added `debug:container --deprecations` command to see compile-time deprecations.
16+
* Added `debug:container --deprecations` option to see compile-time deprecations.
1717

1818
5.0.0
1919
-----

‎src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ protected function configure()
6262
new InputOption('env-vars', null, InputOption::VALUE_NONE, 'Displays environment variables used in the container'),
6363
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
6464
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw description'),
65-
new InputOption('deprecations', null, InputOption::VALUE_NONE, 'To output the deprecations generated when compiling and warming the cache'),
65+
new InputOption('deprecations', null, InputOption::VALUE_NONE, 'Displays deprecations generated when compiling and warming up the container'),
6666
])
6767
->setDescription('Displays current services for an application')
6868
->setHelp(<<<'EOF'
6969
The <info>%command.name%</info> command displays all configured <comment>public</comment> services:
7070
7171
<info>php %command.full_name%</info>
72-
73-
To see deprecations generated during container compilation and cache warmup, use the <info>--deprecations</info> flag:
74-
72+
73+
To see deprecations generated during container compilation and cache warmup, use the <info>--deprecations</info> option:
74+
7575
<info>php %command.full_name% --deprecations</info>
7676
7777
To get specific information about a service, specify its name:
@@ -187,7 +187,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
187187
$errorIo->comment('To search for a specific tag, re-run this command with a search term. (e.g. <comment>debug:container --tag=form.type</comment>)');
188188
} elseif ($input->getOption('parameters')) {
189189
$errorIo->comment('To search for a specific parameter, re-run this command with a search term. (e.g. <comment>debug:container --parameter=kernel.debug</comment>)');
190-
} else {
190+
} elseif (!$input->getOption('deprecations')) {
191191
$errorIo->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
192192
}
193193
}
@@ -202,7 +202,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
202202
*/
203203
protected function validateInput(InputInterface $input)
204204
{
205-
$options = ['tags', 'tag', 'parameters', 'parameter'];
205+
$options = ['tags', 'tag', 'parameters', 'parameter', 'deprecations'];
206206

207207
$optionsCount = 0;
208208
foreach ($options as $option) {
@@ -213,9 +213,9 @@ protected function validateInput(InputInterface $input)
213213

214214
$name = $input->getArgument('name');
215215
if ((null !== $name) && ($optionsCount > 0)) {
216-
throw new InvalidArgumentException('The options tags, tag, parameters & parameter can not be combined with the service name argument.');
216+
throw new InvalidArgumentException('The options tags, tag, parameters, parameter & deprecations can not be combined with the service name argument.');
217217
} elseif ((null === $name) && $optionsCount > 1) {
218-
throw new InvalidArgumentException('The options tags, tag, parameters & parameter can not be combined together.');
218+
throw new InvalidArgumentException('The options tags, tag, parameters, parameter & deprecations can not be combined together.');
219219
}
220220
}
221221

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php
+21-1Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
1313

1414
use Symfony\Component\Console\Exception\LogicException;
15+
use Symfony\Component\Console\Exception\RuntimeException;
1516
use Symfony\Component\DependencyInjection\Alias;
1617
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
1718
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
@@ -195,7 +196,26 @@ protected function describeContainerEnvVars(array $envs, array $options = [])
195196
*/
196197
protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void
197198
{
198-
throw new LogicException('Using the JSON format to print the deprecations is not supported.');
199+
$containerDeprecationFilePath = sprintf('%s/%sDeprecations.log', $builder->getParameter('kernel.cache_dir'), $builder->getParameter('kernel.container_class'));
200+
if (!file_exists($containerDeprecationFilePath)) {
201+
throw new RuntimeException('The deprecation file does not exist, please try warming the cache first.');
202+
}
203+
204+
$logs = unserialize(file_get_contents($containerDeprecationFilePath));
205+
206+
$formattedLogs = [];
207+
$remainingCount = 0;
208+
foreach ($logs as $log) {
209+
$formattedLogs[] = [
210+
'message' => $log['message'],
211+
'file' => $log['file'],
212+
'line' => $log['line'],
213+
'count' => $log['count'],
214+
];
215+
$remainingCount += $log['count'];
216+
}
217+
218+
$this->writeData(['remainingCount' => $remainingCount, 'deprecations' => $formattedLogs], $options);
199219
}
200220

201221
/**

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php
+24-1Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
1313

1414
use Symfony\Component\Console\Exception\LogicException;
15+
use Symfony\Component\Console\Exception\RuntimeException;
1516
use Symfony\Component\DependencyInjection\Alias;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Definition;
@@ -124,7 +125,29 @@ protected function describeContainerService($service, array $options = [], Conta
124125
*/
125126
protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void
126127
{
127-
throw new LogicException('Using the Markdown format to print the deprecations is not supported.');
128+
$containerDeprecationFilePath = sprintf('%s/%sDeprecations.log', $builder->getParameter('kernel.cache_dir'), $builder->getParameter('kernel.container_class'));
129+
if (!file_exists($containerDeprecationFilePath)) {
130+
throw new RuntimeException('The deprecation file does not exist, please try warming the cache first.');
131+
}
132+
133+
$logs = unserialize(file_get_contents($containerDeprecationFilePath));
134+
if (0 === \count($logs)) {
135+
$this->write("## There are no deprecations in the logs!\n");
136+
137+
return;
138+
}
139+
140+
$formattedLogs = [];
141+
$remainingCount = 0;
142+
foreach ($logs as $log) {
143+
$formattedLogs[] = sprintf("- %sx: \"%s\" in %s:%s\n", $log['count'], $log['message'], $log['file'], $log['line']);
144+
$remainingCount += $log['count'];
145+
}
146+
147+
$this->write(sprintf("## Remaining deprecations (%s)\n\n", $remainingCount));
148+
foreach ($formattedLogs as $formattedLog) {
149+
$this->write($formattedLog);
150+
}
128151
}
129152

130153
/**

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ protected function describeContainerDeprecations(ContainerBuilder $builder, arra
396396
$formattedLogs = [];
397397
$remainingCount = 0;
398398
foreach ($logs as $log) {
399-
$formattedLogs[] = sprintf("%sx: %s \n in %s:%s", $log['count'], $log['message'], $log['file'], $log['line']);
399+
$formattedLogs[] = sprintf("%sx: %s\n in %s:%s", $log['count'], $log['message'], $log['file'], $log['line']);
400400
$remainingCount += $log['count'];
401401
}
402402
$options['output']->title(sprintf('Remaining deprecations (%s)', $remainingCount));

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php
+25-1Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
1313

1414
use Symfony\Component\Console\Exception\LogicException;
15+
use Symfony\Component\Console\Exception\RuntimeException;
1516
use Symfony\Component\DependencyInjection\Alias;
1617
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1718
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
@@ -147,7 +148,30 @@ protected function describeContainerEnvVars(array $envs, array $options = [])
147148
*/
148149
protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void
149150
{
150-
throw new LogicException('Using the XML format to print the deprecations is not supported.');
151+
$containerDeprecationFilePath = sprintf('%s/%sDeprecations.log', $builder->getParameter('kernel.cache_dir'), $builder->getParameter('kernel.container_class'));
152+
if (!file_exists($containerDeprecationFilePath)) {
153+
throw new RuntimeException('The deprecation file does not exist, please try warming the cache first.');
154+
}
155+
156+
$logs = unserialize(file_get_contents($containerDeprecationFilePath));
157+
158+
$dom = new \DOMDocument('1.0', 'UTF-8');
159+
$dom->appendChild($deprecationsXML = $dom->createElement('deprecations'));
160+
161+
$formattedLogs = [];
162+
$remainingCount = 0;
163+
foreach ($logs as $log) {
164+
$deprecationsXML->appendChild($deprecationXML = $dom->createElement('deprecation'));
165+
$deprecationXML->setAttribute('count', $log['count']);
166+
$deprecationXML->appendChild($dom->createElement('message', $log['message']));
167+
$deprecationXML->appendChild($dom->createElement('file', $log['file']));
168+
$deprecationXML->appendChild($dom->createElement('line', $log['line']));
169+
$remainingCount += $log['count'];
170+
}
171+
172+
$deprecationsXML->setAttribute('remainingCount', $remainingCount);
173+
174+
$this->writeDocument($dom);
151175
}
152176

153177
/**

‎src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,19 @@ public function getClassDescriptionTestData()
211211
];
212212
}
213213

214+
/**
215+
* @dataProvider getDeprecationsTestData
216+
*/
217+
public function testGetDeprecations(ContainerBuilder $builder, $expectedDescription)
218+
{
219+
$this->assertDescription($expectedDescription, $builder, ['deprecations' => true]);
220+
}
221+
222+
public function getDeprecationsTestData()
223+
{
224+
return $this->getDescriptionTestData(ObjectsProvider::getContainerDeprecations());
225+
}
226+
214227
abstract protected function getDescriptor();
215228

216229
abstract protected function getFormat();

‎src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ public static function getContainerParameter()
8888
];
8989
}
9090

91+
public static function getContainerDeprecations()
92+
{
93+
$builderWithDeprecations = new ContainerBuilder();
94+
$builderWithDeprecations->setParameter('kernel.cache_dir', __DIR__.'/../../Fixtures/Descriptor/cache');
95+
$builderWithDeprecations->setParameter('kernel.container_class', 'KernelContainerWith');
96+
97+
$builderWithoutDeprecations = new ContainerBuilder();
98+
$builderWithoutDeprecations->setParameter('kernel.cache_dir', __DIR__.'/../../Fixtures/Descriptor/cache');
99+
$builderWithoutDeprecations->setParameter('kernel.container_class', 'KernelContainerWithout');
100+
101+
return [
102+
'deprecations' => $builderWithDeprecations,
103+
'deprecations_empty' => $builderWithoutDeprecations,
104+
];
105+
}
106+
91107
public static function getContainerBuilders()
92108
{
93109
$builder1 = new ContainerBuilder();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a:2:{i:0;a:6:{s:4:"type";i:16384;s:7:"message";s:25:"Some deprecation message.";s:4:"file";s:22:"/path/to/some/file.php";s:4:"line";i:39;s:5:"trace";a:0:{}s:5:"count";i:3;}i:1;a:6:{s:4:"type";i:16384;s:7:"message";s:29:"An other deprecation message.";s:4:"file";s:26:"/path/to/an/other/file.php";s:4:"line";i:25;s:5:"trace";a:0:{}s:5:"count";i:2;}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a:0:{}
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"remainingCount": 5,
3+
"deprecations": [
4+
{
5+
"message": "Some deprecation message.",
6+
"file": "\/path\/to\/some\/file.php",
7+
"line": 39,
8+
"count": 3
9+
},
10+
{
11+
"message": "An other deprecation message.",
12+
"file": "\/path\/to\/an\/other\/file.php",
13+
"line": 25,
14+
"count": 2
15+
}
16+
]
17+
}
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Remaining deprecations (5)
2+
3+
- 3x: "Some deprecation message." in /path/to/some/file.php:39
4+
- 2x: "An other deprecation message." in /path/to/an/other/file.php:25
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
Remaining deprecations (5)
3+
==========================
4+
5+
* 3x: Some deprecation message.
6+
in /path/to/some/file.php:39
7+
* 2x: An other deprecation message.
8+
in /path/to/an/other/file.php:25
9+
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<deprecations remainingCount="5">
3+
<deprecation count="3">
4+
<message>Some deprecation message.</message>
5+
<file>/path/to/some/file.php</file>
6+
<line>39</line>
7+
</deprecation>
8+
<deprecation count="2">
9+
<message>An other deprecation message.</message>
10+
<file>/path/to/an/other/file.php</file>
11+
<line>25</line>
12+
</deprecation>
13+
</deprecations>
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"remainingCount": 0,
3+
"deprecations": []
4+
}
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## There are no deprecations in the logs!
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
 
3+
 [OK] There are no deprecations in the logs! 
4+
 
5+
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<deprecations remainingCount="0"/>

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerDebugCommandTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerDebugCommandTest.php
+4-19Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ public function testGetDeprecation()
162162
$tester->run(['command' => 'debug:container', '--deprecations' => true]);
163163

164164
$this->assertSame(0, $tester->getStatusCode());
165-
$this->assertContains('Symfony\Bundle\FrameworkBundle\Controller\Controller', $tester->getDisplay());
166-
$this->assertContains('/home/hamza/projet/contrib/sf/vendor/symfony/framework-bundle/Controller/Controller.php', $tester->getDisplay());
165+
$this->assertStringContainsString('Symfony\Bundle\FrameworkBundle\Controller\Controller', $tester->getDisplay());
166+
$this->assertStringContainsString('/home/hamza/projet/contrib/sf/vendor/symfony/framework-bundle/Controller/Controller.php', $tester->getDisplay());
167167
}
168168

169169
public function testGetDeprecationNone()
@@ -182,7 +182,7 @@ public function testGetDeprecationNone()
182182
$tester->run(['command' => 'debug:container', '--deprecations' => true]);
183183

184184
$this->assertSame(0, $tester->getStatusCode());
185-
$this->assertContains('[OK] There are no deprecations in the logs!', $tester->getDisplay());
185+
$this->assertStringContainsString('[OK] There are no deprecations in the logs!', $tester->getDisplay());
186186
}
187187

188188
public function testGetDeprecationNoFile(): void
@@ -200,22 +200,7 @@ public function testGetDeprecationNoFile(): void
200200
$tester->run(['command' => 'debug:container', '--deprecations' => true]);
201201

202202
$this->assertSame(0, $tester->getStatusCode());
203-
$this->assertContains('[WARNING] The deprecation file does not exist', $tester->getDisplay());
204-
}
205-
206-
public function testGetDeprecationXml(): void
207-
{
208-
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml', 'debug' => true]);
209-
$application = new Application(static::$kernel);
210-
$application->setAutoExit(false);
211-
212-
@unlink(static::$container->getParameter('debug.container.dump'));
213-
214-
$tester = new ApplicationTester($application);
215-
$tester->run(['command' => 'debug:container', '--deprecations' => true, '--format' => 'xml']);
216-
217-
$this->assertSame(1, $tester->getStatusCode());
218-
$this->assertContains('Using the XML format to print the deprecations is not supported.', $tester->getDisplay());
203+
$this->assertStringContainsString('[WARNING] The deprecation file does not exist', $tester->getDisplay());
219204
}
220205

221206
public function provideIgnoreBackslashWhenFindingService()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.