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

Appearance settings

Commit 12c6dbf

Browse filesBrowse files
committed
bug #46747 Fix global state pollution between tests run with ApplicationTester (Seldaek)
This PR was merged into the 4.4 branch. Discussion ---------- Fix global state pollution between tests run with ApplicationTester | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> If you run a test with ApplicationTester which includes -v or similar flag, then https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/Console/Application.php#L985-L989 leaves the env in a dirty state, and all tests following also use -v. Commits ------- f4c81f1 Fix global state pollution between tests run with ApplicationTester
2 parents c299069 + f4c81f1 commit 12c6dbf
Copy full SHA for 12c6dbf

File tree

Expand file treeCollapse file tree

1 file changed

+29
-9
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+29
-9
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tester/ApplicationTester.php
+29-9Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,37 @@ public function __construct(Application $application)
5454
*/
5555
public function run(array $input, $options = [])
5656
{
57-
$this->input = new ArrayInput($input);
58-
if (isset($options['interactive'])) {
59-
$this->input->setInteractive($options['interactive']);
60-
}
57+
$prevShellVerbosity = getenv('SHELL_VERBOSITY');
6158

62-
if ($this->inputs) {
63-
$this->input->setStream(self::createStream($this->inputs));
64-
}
59+
try {
60+
$this->input = new ArrayInput($input);
61+
if (isset($options['interactive'])) {
62+
$this->input->setInteractive($options['interactive']);
63+
}
6564

66-
$this->initOutput($options);
65+
if ($this->inputs) {
66+
$this->input->setStream(self::createStream($this->inputs));
67+
}
6768

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.