Skip to content

[Dotenv] Run test in a separate process to have clean global state #47014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Symfony/Component/Dotenv/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -117,6 +119,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
if ($input->mustSuggestArgumentValuesFor('filter')) {
$suggestions->suggestValues($this->getAvailableVars());
}
}

private function getVariables(array $envFiles, ?string $nameFilter): array
{
$vars = $this->getAvailableVars();
Expand Down
10 changes: 8 additions & 2 deletions src/Symfony/Component/Dotenv/Tests/Command/DebugCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Dotenv\Tests\Command;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\FormatterHelper;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Tester\CommandCompletionTester;
Expand Down Expand Up @@ -207,6 +208,9 @@ public function testScenario2InProdEnvWithNameFilterPrefix()
$this->assertStringContainsString('TEST 1234 1234 1234 0000', $output);
}

/**
* @runInSeparateProcess
*/
public function testCompletion()
{
$env = 'prod';
Expand All @@ -216,8 +220,10 @@ public function testCompletion()
(new Dotenv('TEST_ENV_KEY'))->bootEnv($projectDirectory.'/.env');

$command = new DebugCommand($env, $projectDirectory);
$tester = new CommandCompletionTester($command);
$this->assertSame(['FOO', 'HELLO', 'TEST', 'TEST123'], $tester->complete(['']));
$application = new Application();
$application->add($command);
$tester = new CommandCompletionTester($application->get('debug:dotenv'));
$this->assertSame(['FOO', 'TEST'], $tester->complete(['']));
}

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