Skip to content

Commit b1aa9ac

Browse files
committed
minor #24073 [Console] Fix BC break in console.command.ids parameter (chalasr)
This PR was merged into the 3.4 branch. Discussion ---------- [Console] Fix BC break in console.command.ids parameter | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony/flex#142 (comment) | License | MIT | Doc PR | n/a To make command services lazy loaded when their name is known, we need to exclude them from [runtime registration of other (non lazy-loadable) command services](https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Console/Application.php#L176). We also need to have them in the `console.command.ids` parameter in order to [not register them by convention](https://github.com/symfony/symfony/blob/3.4/src/Symfony/Component/HttpKernel/Bundle/Bundle.php#L188). It is managed using `false` as values instead of ids for the parameter, [excluding false values from runtime registration](https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Console/Application.php#L177). Problem is that it makes FrameworkBundle's 3.3 Application incompatible with Console 3.4+ given the check for `false` is missing. This PR fixes it using another parameter referencing ids of command services which can be lazy loaded. I would be happy to not add the parameter if someone has a suggestion that allows to do so. Commits ------- 99e95c3d2d Fix BC break in console.command.ids parameter
2 parents 2301ffa + 266df0e commit b1aa9ac

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Console/Application.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,9 @@ protected function registerCommands()
173173
}
174174

175175
if ($container->hasParameter('console.command.ids')) {
176+
$lazyCommandIds = $container->hasParameter('console.lazy_command.ids') ? $container->getParameter('console.lazy_command.ids') : array();
176177
foreach ($container->getParameter('console.command.ids') as $id) {
177-
if (false !== $id) {
178+
if (!isset($lazyCommandIds[$id])) {
178179
try {
179180
$this->add($container->get($id));
180181
} catch (\Exception $e) {

Tests/Console/ApplicationTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,16 @@ private function getKernel(array $bundles, $useDispatcher = false)
183183
}
184184

185185
$container
186-
->expects($this->once())
186+
->expects($this->exactly(2))
187187
->method('hasParameter')
188-
->with($this->equalTo('console.command.ids'))
189-
->will($this->returnValue(true))
188+
->withConsecutive(array('console.command.ids'), array('console.lazy_command.ids'))
189+
->willReturnOnConsecutiveCalls(true, true)
190190
;
191191
$container
192-
->expects($this->once())
192+
->expects($this->exactly(2))
193193
->method('getParameter')
194-
->with($this->equalTo('console.command.ids'))
195-
->will($this->returnValue(array()))
194+
->withConsecutive(array('console.lazy_command.ids'), array('console.command.ids'))
195+
->willReturnOnConsecutiveCalls(array(), array())
196196
;
197197

198198
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();

0 commit comments

Comments
 (0)