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 ee6391e

Browse filesBrowse files
noemi-salaunnicolas-grekas
authored andcommitted
[FrameworkBundle] add all formats support for debug:container --deprecations command
1 parent 161f659 commit ee6391e
Copy full SHA for ee6391e
Expand file treeCollapse file tree

20 files changed

+169
-31
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
+5-5Lines changed: 5 additions & 5 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
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ abstract protected function describeContainerService($service, array $options =
123123
*/
124124
abstract protected function describeContainerServices(ContainerBuilder $builder, array $options = []);
125125

126-
abstract protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []);
126+
abstract protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void;
127127

128128
abstract protected function describeContainerDefinition(Definition $definition, array $options = []);
129129

‎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;
@@ -156,7 +157,26 @@ protected function describeContainerEnvVars(array $envs, array $options = [])
156157

157158
protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void
158159
{
159-
throw new LogicException('Using the JSON format to print the deprecations is not supported.');
160+
$containerDeprecationFilePath = sprintf('%s/%sDeprecations.log', $builder->getParameter('kernel.cache_dir'), $builder->getParameter('kernel.container_class'));
161+
if (!file_exists($containerDeprecationFilePath)) {
162+
throw new RuntimeException('The deprecation file does not exist, please try warming the cache first.');
163+
}
164+
165+
$logs = unserialize(file_get_contents($containerDeprecationFilePath));
166+
167+
$formattedLogs = [];
168+
$remainingCount = 0;
169+
foreach ($logs as $log) {
170+
$formattedLogs[] = [
171+
'message' => $log['message'],
172+
'file' => $log['file'],
173+
'line' => $log['line'],
174+
'count' => $log['count'],
175+
];
176+
$remainingCount += $log['count'];
177+
}
178+
179+
$this->writeData(['remainingCount' => $remainingCount, 'deprecations' => $formattedLogs], $options);
160180
}
161181

162182
private function writeData(array $data, array $options)

‎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;
@@ -106,7 +107,29 @@ protected function describeContainerService($service, array $options = [], Conta
106107

107108
protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void
108109
{
109-
throw new LogicException('Using the Markdown format to print the deprecations is not supported.');
110+
$containerDeprecationFilePath = sprintf('%s/%sDeprecations.log', $builder->getParameter('kernel.cache_dir'), $builder->getParameter('kernel.container_class'));
111+
if (!file_exists($containerDeprecationFilePath)) {
112+
throw new RuntimeException('The deprecation file does not exist, please try warming the cache first.');
113+
}
114+
115+
$logs = unserialize(file_get_contents($containerDeprecationFilePath));
116+
if (0 === \count($logs)) {
117+
$this->write("## There are no deprecations in the logs!\n");
118+
119+
return;
120+
}
121+
122+
$formattedLogs = [];
123+
$remainingCount = 0;
124+
foreach ($logs as $log) {
125+
$formattedLogs[] = sprintf("- %sx: \"%s\" in %s:%s\n", $log['count'], $log['message'], $log['file'], $log['line']);
126+
$remainingCount += $log['count'];
127+
}
128+
129+
$this->write(sprintf("## Remaining deprecations (%s)\n\n", $remainingCount));
130+
foreach ($formattedLogs as $formattedLog) {
131+
$this->write($formattedLog);
132+
}
110133
}
111134

112135
protected function describeContainerServices(ContainerBuilder $builder, array $options = [])

‎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
@@ -372,7 +372,7 @@ protected function describeContainerDeprecations(ContainerBuilder $builder, arra
372372
$formattedLogs = [];
373373
$remainingCount = 0;
374374
foreach ($logs as $log) {
375-
$formattedLogs[] = sprintf("%sx: %s \n in %s:%s", $log['count'], $log['message'], $log['file'], $log['line']);
375+
$formattedLogs[] = sprintf("%sx: %s\n in %s:%s", $log['count'], $log['message'], $log['file'], $log['line']);
376376
$remainingCount += $log['count'];
377377
}
378378
$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;
@@ -108,7 +109,30 @@ protected function describeContainerEnvVars(array $envs, array $options = [])
108109

109110
protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void
110111
{
111-
throw new LogicException('Using the XML format to print the deprecations is not supported.');
112+
$containerDeprecationFilePath = sprintf('%s/%sDeprecations.log', $builder->getParameter('kernel.cache_dir'), $builder->getParameter('kernel.container_class'));
113+
if (!file_exists($containerDeprecationFilePath)) {
114+
throw new RuntimeException('The deprecation file does not exist, please try warming the cache first.');
115+
}
116+
117+
$logs = unserialize(file_get_contents($containerDeprecationFilePath));
118+
119+
$dom = new \DOMDocument('1.0', 'UTF-8');
120+
$dom->appendChild($deprecationsXML = $dom->createElement('deprecations'));
121+
122+
$formattedLogs = [];
123+
$remainingCount = 0;
124+
foreach ($logs as $log) {
125+
$deprecationsXML->appendChild($deprecationXML = $dom->createElement('deprecation'));
126+
$deprecationXML->setAttribute('count', $log['count']);
127+
$deprecationXML->appendChild($dom->createElement('message', $log['message']));
128+
$deprecationXML->appendChild($dom->createElement('file', $log['file']));
129+
$deprecationXML->appendChild($dom->createElement('line', $log['line']));
130+
$remainingCount += $log['count'];
131+
}
132+
133+
$deprecationsXML->setAttribute('remainingCount', $remainingCount);
134+
135+
$this->writeDocument($dom);
112136
}
113137

114138
private function writeDocument(\DOMDocument $dom)

‎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
+5-20Lines changed: 5 additions & 20 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,10 +182,10 @@ 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

188-
public function testGetDeprecationNoFile(): void
188+
public function testGetDeprecationNoFile()
189189
{
190190
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml', 'debug' => true]);
191191
$path = sprintf('%s/%sDeprecations.log', static::$kernel->getContainer()->getParameter('kernel.cache_dir'), static::$kernel->getContainer()->getParameter('kernel.container_class'));
@@ -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.