Skip to content

Commit 570e67d

Browse files
committed
[Console] Restore SHELL_VERBOSITY after a command is ran
1 parent fcb8989 commit 570e67d

File tree

2 files changed

+27
-29
lines changed

2 files changed

+27
-29
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ public function run(?InputInterface $input = null, ?OutputInterface $output = nu
187187
}
188188
}
189189

190+
$prevShellVerbosity = getenv('SHELL_VERBOSITY');
191+
190192
try {
191193
$this->configureIO($input, $output);
192194

@@ -224,6 +226,22 @@ public function run(?InputInterface $input = null, ?OutputInterface $output = nu
224226
$phpHandler[0]->setExceptionHandler($finalHandler);
225227
}
226228
}
229+
230+
// SHELL_VERBOSITY is set by Application::configureIO so we need to unset/reset it
231+
// to its previous value to avoid one command verbosity to spread to other commands
232+
if (false === $prevShellVerbosity) {
233+
if (\function_exists('putenv')) {
234+
@putenv('SHELL_VERBOSITY');
235+
}
236+
unset($_ENV['SHELL_VERBOSITY']);
237+
unset($_SERVER['SHELL_VERBOSITY']);
238+
} else {
239+
if (\function_exists('putenv')) {
240+
@putenv('SHELL_VERBOSITY='.$prevShellVerbosity);
241+
}
242+
$_ENV['SHELL_VERBOSITY'] = $prevShellVerbosity;
243+
$_SERVER['SHELL_VERBOSITY'] = $prevShellVerbosity;
244+
}
227245
}
228246

229247
if ($this->autoExit) {

src/Symfony/Component/Console/Tester/ApplicationTester.php

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,37 +47,17 @@ public function __construct(
4747
*/
4848
public function run(array $input, array $options = []): int
4949
{
50-
$prevShellVerbosity = getenv('SHELL_VERBOSITY');
51-
52-
try {
53-
$this->input = new ArrayInput($input);
54-
if (isset($options['interactive'])) {
55-
$this->input->setInteractive($options['interactive']);
56-
}
50+
$this->input = new ArrayInput($input);
51+
if (isset($options['interactive'])) {
52+
$this->input->setInteractive($options['interactive']);
53+
}
5754

58-
if ($this->inputs) {
59-
$this->input->setStream(self::createStream($this->inputs));
60-
}
55+
if ($this->inputs) {
56+
$this->input->setStream(self::createStream($this->inputs));
57+
}
6158

62-
$this->initOutput($options);
59+
$this->initOutput($options);
6360

64-
return $this->statusCode = $this->application->run($this->input, $this->output);
65-
} finally {
66-
// SHELL_VERBOSITY is set by Application::configureIO so we need to unset/reset it
67-
// to its previous value to avoid one test's verbosity to spread to the following tests
68-
if (false === $prevShellVerbosity) {
69-
if (\function_exists('putenv')) {
70-
@putenv('SHELL_VERBOSITY');
71-
}
72-
unset($_ENV['SHELL_VERBOSITY']);
73-
unset($_SERVER['SHELL_VERBOSITY']);
74-
} else {
75-
if (\function_exists('putenv')) {
76-
@putenv('SHELL_VERBOSITY='.$prevShellVerbosity);
77-
}
78-
$_ENV['SHELL_VERBOSITY'] = $prevShellVerbosity;
79-
$_SERVER['SHELL_VERBOSITY'] = $prevShellVerbosity;
80-
}
81-
}
61+
return $this->statusCode = $this->application->run($this->input, $this->output);
8262
}
8363
}

0 commit comments

Comments
 (0)