Skip to content
Permalink
Browse files

feature #30887 [FrameworkBundle] fix search in debug autowiring (sez-…

…open)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[FrameworkBundle] fix search in debug autowiring

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #30493   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        |

<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->

Taking #30522 and finishing it with @nicolas-grekas comments.
Is the sentence ok ?

Commits
-------

fec4bea fix debug:autowiringcommand
  • Loading branch information...
nicolas-grekas committed Apr 7, 2019
2 parents 50c22b3 + fec4bea commit 65b46a532c3f48fddc683c8cccbc0be5d393ffb7
@@ -100,6 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$hasAlias = [];
$all = $input->getOption('all');
$previousId = '-';
$serviceIdsNb = 0;
foreach ($serviceIds as $serviceId) {
$text = [];
if (0 !== strpos($serviceId, $previousId)) {
@@ -127,11 +128,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
$serviceLine .= ' - <fg=magenta>deprecated</>';
}
} elseif (!$all) {
++$serviceIdsNb;
continue;
}
$text[] = $serviceLine;
$io->text($text);
}
$io->newLine();
if (0 < $serviceIdsNb) {
$io->text(sprintf('%s more concrete service%s would be displayed when adding the "--all" option.', $serviceIdsNb, $serviceIdsNb > 1 ? 's' : ''));
}
if ($all) {
$io->text('Pro-tip: use interfaces in your type-hints instead of classes to benefit from the dependency inversion principle.');
}
$io->newLine();
}
@@ -72,4 +72,29 @@ public function testSearchNoResults()
$this->assertContains('No autowirable classes or interfaces found matching "foo_fake"', $tester->getErrorOutput());
$this->assertEquals(1, $tester->getStatusCode());
}
public function testSearchNotAliasedService()
{
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml']);
$application = new Application(static::$kernel);
$application->setAutoExit(false);
$tester = new ApplicationTester($application);
$tester->run(['command' => 'debug:autowiring', 'search' => 'redirect']);
$this->assertContains(' more concrete service would be displayed when adding the "--all" option.', $tester->getDisplay());
}
public function testSearchNotAliasedServiceWithAll()
{
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml']);
$application = new Application(static::$kernel);
$application->setAutoExit(false);
$tester = new ApplicationTester($application);
$tester->run(['command' => 'debug:autowiring', 'search' => 'redirect', '--all' => true]);
$this->assertContains('Pro-tip: use interfaces in your type-hints instead of classes to benefit from the dependency inversion principle.', $tester->getDisplay());
}
}

0 comments on commit 65b46a5

Please sign in to comment.
You can’t perform that action at this time.