8000 feature #30887 [FrameworkBundle] fix search in debug autowiring (sez-… · symfony/symfony@65b46a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 65b46a5

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
2 parents 50c22b3 + fec4bea commit 65b46a5

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
100100
$hasAlias = [];
101101
$all = $input->getOption('all');
102102
$previousId = '-';
103+
$serviceIdsNb = 0;
103104
foreach ($serviceIds as $serviceId) {
104105
$text = [];
105106
if (0 !== strpos($serviceId, $previousId)) {
@@ -127,11 +128,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
127128
$serviceLine .= ' - <fg=magenta>deprecated</>';
128129
}
129130
} elseif (!$all) {
131+
++$serviceIdsNb;
130132
continue;
131133
}
132134
$text[] = $serviceLine;
133135
$io->text($text);
134136
}
137+
138+
$io->newLine();
139+
140+
if (0 < $serviceIdsNb) {
141+
$io->text(sprintf('%s more concrete service%s would be displayed when adding the "--all" option.', $serviceIdsNb, $serviceIdsNb > 1 ? 's' : ''));
142+
}
143+
if ($all) {
144+
$io->text('Pro-tip: use interfaces in your type-hints instead of classes to benefit from the dependency inversion principle.');
145+
}
146+
135147
$io->newLine();
136148
}
137149

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/DebugAutowiringCommandTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,29 @@ public function testSearchNoResults()
7272
$this->assertContains('No autowirable classes or interfaces found matching "foo_fake"', $tester->getErrorOutput());
7373
$this->assertEquals(1, $tester->getStatusCode());
7474
}
75+
76+
public function testSearchNotAliasedService()
77+
{
78+
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml']);
79+
80+
$application = new Application(static::$kernel);
81+
$application->setAutoExit(false);
82+
83+
$tester = new ApplicationTester($application);
84+
$tester->run(['command' => 'debug:autowiring', 'search' => 'redirect']);
85+
86+
$this->assertContains(' more concrete service would be displayed when adding the "--all" option.', $tester->getDisplay());
87+
}
88+
89+
public function testSearchNotAliasedServiceWithAll()
90+
{
91+
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml']);
92+
93+
$application = new Application(static::$kernel);
94+
$application->setAutoExit(false);
95+
96+
$tester = new ApplicationTester($application);
97+
$tester->run(['command' => 'debug:autowiring', 'search' => 'redirect', '--all' => true]);
98+
$this->assertContains('Pro-tip: use interfaces in your type-hints instead of classes to benefit from the dependency inversion principle.', $tester->getDisplay());
99+
}
75100
}

0 commit comments

Comments
 (0)
0