Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit12a56eb

Browse files
committed
[FrameworkBundle]: Fail properly on unregistrable command
1 parentf3a9a0e commit12a56eb

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
useSymfony\Component\HttpKernel\Kernel;
2525
useSymfony\Component\HttpKernel\KernelInterface;
2626

27+
usefunctionmax;
28+
2729
/**
2830
* @author Fabien Potencier <fabien@symfony.com>
2931
*/
@@ -68,24 +70,29 @@ public function doRun(InputInterface $input, OutputInterface $output): int
6870
{
6971
$this->registerCommands();
7072

73+
$statusCode = Command::SUCCESS;
7174
if ($this->registrationErrors) {
75+
$statusCode = Command::FAILURE;
76+
7277
$this->renderRegistrationErrors($input,$output);
7378
}
7479

7580
$this->setDispatcher($this->kernel->getContainer()->get('event_dispatcher'));
7681

77-
returnparent::doRun($input,$output);
82+
returnmax($statusCode,parent::doRun($input,$output));
7883
}
7984

8085
protectedfunctiondoRunCommand(Command$command,InputInterface$input,OutputInterface$output):int
8186
{
8287
if (!$commandinstanceof ListCommand) {
88+
$statusCode = Command::SUCCESS;
8389
if ($this->registrationErrors) {
90+
$statusCode = Command::FAILURE;
8491
$this->renderRegistrationErrors($input,$output);
8592
$this->registrationErrors = [];
8693
}
8794

88-
returnparent::doRunCommand($command,$input,$output);
95+
returnmax($statusCode,parent::doRunCommand($command,$input,$output));
8996
}
9097

9198
$returnCode =parent::doRunCommand($command,$input,$output);

‎src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function testBundleCommandCanOverriddeAPreExistingCommandWithTheSameName(
123123
$this->assertSame($newCommand,$application->get('example'));
124124
}
125125

126-
publicfunctiontestRunOnlyWarnsOnUnregistrableCommand()
126+
publicfunctiontestUnregistrableCommandsAreConsideredFailure()
127127
{
128128
$container =newContainerBuilder();
129129
$container->register('event_dispatcher', EventDispatcher::class);
@@ -147,7 +147,7 @@ public function testRunOnlyWarnsOnUnregistrableCommand()
147147
$tester->run(['command' =>'fine']);
148148
$output =$tester->getDisplay();
149149

150-
$tester->assertCommandIsSuccessful();
150+
$this->assertSame(1,$tester->getStatusCode());
151151
$this->assertStringContainsString('Some commands could not be registered:',$output);
152152
$this->assertStringContainsString('throwing',$output);
153153
$this->assertStringContainsString('fine',$output);
@@ -180,7 +180,7 @@ public function testRegistrationErrorsAreDisplayedOnCommandNotFound()
180180
$this->assertStringContainsString('Command "fine" is not defined.',$output);
181181
}
182182

183-
publicfunctiontestRunOnlyWarnsOnUnregistrableCommandAtTheEnd()
183+
publicfunctiontestRunFailsOnUnregistrableCommandAtTheEnd()
184184
{
185185
$container =newContainerBuilder();
186186
$container->register('event_dispatcher', EventDispatcher::class);
@@ -204,7 +204,7 @@ public function testRunOnlyWarnsOnUnregistrableCommandAtTheEnd()
204204
$tester =newApplicationTester($application);
205205
$tester->run(['command' =>'list']);
206206

207-
$tester->assertCommandIsSuccessful();
207+
$this->assertSame(1,$tester->getStatusCode());
208208
$display =explode('List commands',$tester->getDisplay());
209209

210210
$this->assertStringContainsString(trim('[WARNING] Some commands could not be registered:'),trim($display[1]));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp