Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8be4d28

Browse files
committed
minor #47014 [Dotenv] Run test in a separate process to have clean global state (rmikalkenas)
This PR was merged into the 6.2 branch. Discussion ---------- [Dotenv] Run test in a separate process to have clean global state | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Fix #... | License | MIT | Doc PR | symfony/symfony-docs#... A fix to comment: #46502 (comment) cc @chalasr Commits ------- be3782c [Dotenv] Run test in a separate process to have clean global state
2 parents 6babf86 + be3782c commit 8be4d28

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/Symfony/Component/Dotenv/Command/DebugCommand.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Symfony\Component\Console\Attribute\AsCommand;
1515
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Completion\CompletionInput;
17+
use Symfony\Component\Console\Completion\CompletionSuggestions;
1618
use Symfony\Component\Console\Input\InputArgument;
1719
use Symfony\Component\Console\Input\InputInterface;
1820
use Symfony\Component\Console\Output\OutputInterface;
@@ -117,6 +119,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
117119
return 0;
118120
}
119121

122+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
123+
{
124+
if ($input->mustSuggestArgumentValuesFor('filter')) {
125+
$suggestions->suggestValues($this->getAvailableVars());
126+
}
127+
}
128+
120129
private function getVariables(array $envFiles, ?string $nameFilter): array
121130
{
122131
$vars = $this->getAvailableVars();

src/Symfony/Component/Dotenv/Tests/Command/DebugCommandTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Dotenv\Tests\Command;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Console\Application;
1516
use Symfony\Component\Console\Helper\FormatterHelper;
1617
use Symfony\Component\Console\Helper\HelperSet;
1718
use Symfony\Component\Console\Tester\CommandCompletionTester;
@@ -207,6 +208,9 @@ public function testScenario2InProdEnvWithNameFilterPrefix()
207208
$this->assertStringContainsString('TEST 1234 1234 1234 0000', $output);
208209
}
209210

211+
/**
212+
* @runInSeparateProcess
213+
*/
210214
public function testCompletion()
211215
{
212216
$env = 'prod';
@@ -216,8 +220,10 @@ public function testCompletion()
216220
(new Dotenv('TEST_ENV_KEY'))->bootEnv($projectDirectory.'/.env');
217221

218222
$command = new DebugCommand($env, $projectDirectory);
219-
$tester = new CommandCompletionTester($command);
220-
$this->assertSame(['FOO', 'HELLO', 'TEST', 'TEST123'], $tester->complete(['']));
223+
$application = new Application();
224+
$application->add($command);
225+
$tester = new CommandCompletionTester($application->get('debug:dotenv'));
226+
$this->assertSame(['FOO', 'TEST'], $tester->complete(['']));
221227
}
222228

223229
private function executeCommand(string $projectDirectory, string $env, array $input = []): string

0 commit comments

Comments
 (0)