mirror of
https://github.com/shlinkio/shlink.git
synced 2026-02-28 04:03:12 +08:00
Add ReadEnvVarCommand test
This commit is contained in:
54
module/CLI/test/Command/Config/ReadEnvVarCommandTest.php
Normal file
54
module/CLI/test/Command/Config/ReadEnvVarCommandTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\CLI\Command\Config;
|
||||
|
||||
use Monolog\Test\TestCase;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Shlinkio\Shlink\CLI\Command\Config\ReadEnvVarCommand;
|
||||
use Shlinkio\Shlink\Core\Config\EnvVars;
|
||||
use ShlinkioTest\Shlink\CLI\Util\CliTestUtils;
|
||||
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class ReadEnvVarCommandTest extends TestCase
|
||||
{
|
||||
private CommandTester $commandTester;
|
||||
private string $envVarValue = 'the_env_var_value';
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->commandTester = CliTestUtils::testerForCommand(new ReadEnvVarCommand(fn () => $this->envVarValue));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function errorIsThrownIfProvidedEnvVarIsInvalid(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('foo is not a valid Shlink environment variable');
|
||||
|
||||
$this->commandTester->execute(['envVar' => 'foo']);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function valueIsPrintedIfProvidedEnvVarIsValid(): void
|
||||
{
|
||||
$this->commandTester->execute(['envVar' => EnvVars::BASE_PATH->value]);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
|
||||
self::assertStringNotContainsString('Select the env var to read', $output);
|
||||
self::assertStringContainsString($this->envVarValue, $output);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function envVarNameIsRequestedIfArgumentIsMissing(): void
|
||||
{
|
||||
$this->commandTester->setInputs([EnvVars::BASE_PATH->value]);
|
||||
$this->commandTester->execute([]);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
|
||||
self::assertStringContainsString('Select the env var to read', $output);
|
||||
self::assertStringContainsString($this->envVarValue, $output);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user