-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create RedisDecodeCredentialsConfigOption
- Loading branch information
Showing
6 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Config/Option/Redis/RedisDecodeCredentialsConfigOption.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shlinkio\Shlink\Installer\Config\Option\Redis; | ||
|
||
use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption; | ||
use Shlinkio\Shlink\Installer\Config\Option\DependentConfigOptionInterface; | ||
use Symfony\Component\Console\Style\StyleInterface; | ||
|
||
/** @deprecated */ | ||
class RedisDecodeCredentialsConfigOption extends BaseConfigOption implements DependentConfigOptionInterface | ||
{ | ||
public function getEnvVar(): string | ||
{ | ||
return 'REDIS_DECODE_CREDENTIALS'; | ||
} | ||
|
||
public function shouldBeAsked(array $currentOptions): bool | ||
{ | ||
$isRedisEnabled = $currentOptions[RedisServersConfigOption::ENV_VAR] ?? null; | ||
return $isRedisEnabled !== null && parent::shouldBeAsked($currentOptions); | ||
} | ||
|
||
public function ask(StyleInterface $io, array $currentOptions): bool | ||
{ | ||
return $io->confirm( | ||
'Do you want redis credentials to be URL-decoded? ' | ||
. '(If you provided servers with URL-encoded credentials, this should be "yes")', | ||
false, | ||
); | ||
} | ||
|
||
public function getDependentOption(): string | ||
{ | ||
return RedisServersConfigOption::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
test/Config/Option/Redis/RedisDecodeCredentialsConfigOptionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ShlinkioTest\Shlink\Installer\Config\Option\Redis; | ||
|
||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
use Shlinkio\Shlink\Installer\Config\Option\Redis\RedisDecodeCredentialsConfigOption; | ||
use Shlinkio\Shlink\Installer\Config\Option\Redis\RedisServersConfigOption; | ||
use Symfony\Component\Console\Style\StyleInterface; | ||
|
||
class RedisDecodeCredentialsConfigOptionTest extends TestCase | ||
{ | ||
private RedisDecodeCredentialsConfigOption $configOption; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->configOption = new RedisDecodeCredentialsConfigOption(); | ||
} | ||
|
||
#[Test] | ||
public function returnsExpectedConfig(): void | ||
{ | ||
self::assertEquals('REDIS_DECODE_CREDENTIALS', $this->configOption->getEnvVar()); | ||
} | ||
|
||
#[Test] | ||
public function expectedQuestionIsAsked(): void | ||
{ | ||
$io = $this->createMock(StyleInterface::class); | ||
$io->expects($this->once())->method('confirm')->with( | ||
'Do you want redis credentials to be URL-decoded? ' | ||
. '(If you provided servers with URL-encoded credentials, this should be "yes")', | ||
false, | ||
)->willReturn(true); | ||
|
||
$answer = $this->configOption->ask($io, []); | ||
|
||
self::assertEquals(true, $answer); | ||
} | ||
|
||
#[Test, DataProvider('provideCurrentOptions')] | ||
public function shouldBeCalledOnlyIfItDoesNotYetExist(array $currentOptions, bool $expected): void | ||
{ | ||
self::assertEquals($expected, $this->configOption->shouldBeAsked($currentOptions)); | ||
} | ||
|
||
public static function provideCurrentOptions(): iterable | ||
{ | ||
yield 'not exists in config' => [[], false]; | ||
yield 'exists in config' => [['REDIS_DECODE_CREDENTIALS' => true], false]; | ||
yield 'redis enabled in config' => [[RedisServersConfigOption::ENV_VAR => 'bar'], true]; | ||
} | ||
|
||
#[Test] | ||
public function dependsOnRedisServer(): void | ||
{ | ||
self::assertEquals(RedisServersConfigOption::class, $this->configOption->getDependentOption()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters