-
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.
Merge pull request #81 from acelaya-forks/feature/geolite-license
Feature/geolite license
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 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
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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shlinkio\Shlink\Installer\Config\Option; | ||
|
||
use Shlinkio\Shlink\Config\Collection\PathCollection; | ||
use Symfony\Component\Console\Style\StyleInterface; | ||
|
||
class GeoLiteLicenseKeyConfigOption extends BaseConfigOption | ||
{ | ||
public function getConfigPath(): array | ||
{ | ||
return ['geolite2', 'license_key']; | ||
} | ||
|
||
public function ask(StyleInterface $io, PathCollection $currentOptions): string | ||
{ | ||
// TODO For Shlink 3.0, this option should be mandatory. The default value should be removed | ||
return $io->ask( | ||
'Provide a GeoLite2 license key. (Leave empty to use default one, but it is ' | ||
. '<options=bold>strongly recommended</> to get your own. ' | ||
. 'Go to https://shlink.io/documentation/geolite-license-key to know how to get it)', | ||
) ?? 'G4Lm0C60yJsnkdPi'; | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ShlinkioTest\Shlink\Installer\Config\Option; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Shlinkio\Shlink\Config\Collection\PathCollection; | ||
use Shlinkio\Shlink\Installer\Config\Option\GeoLiteLicenseKeyConfigOption; | ||
use Symfony\Component\Console\Style\StyleInterface; | ||
|
||
class GeoLiteLicenseKeyConfigOptionTest extends TestCase | ||
{ | ||
private GeoLiteLicenseKeyConfigOption $configOption; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->configOption = new GeoLiteLicenseKeyConfigOption(); | ||
} | ||
|
||
/** @test */ | ||
public function returnsExpectedConfig(): void | ||
{ | ||
$this->assertEquals(['geolite2', 'license_key'], $this->configOption->getConfigPath()); | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider provideAnswers | ||
*/ | ||
public function expectedQuestionIsAsked(?string $answer, string $expectedResult): void | ||
{ | ||
$io = $this->prophesize(StyleInterface::class); | ||
$ask = $io->ask( | ||
'Provide a GeoLite2 license key. (Leave empty to use default one, but it is ' | ||
. '<options=bold>strongly recommended</> to get your own. ' | ||
. 'Go to https://shlink.io/documentation/geolite-license-key to know how to get it)', | ||
)->willReturn($answer); | ||
|
||
$result = $this->configOption->ask($io->reveal(), new PathCollection()); | ||
|
||
$this->assertEquals($expectedResult, $result); | ||
$ask->shouldHaveBeenCalledOnce(); | ||
} | ||
|
||
public function provideAnswers(): iterable | ||
{ | ||
yield 'no answer' => [null, 'G4Lm0C60yJsnkdPi']; | ||
yield 'answer' => ['foo', 'foo']; | ||
} | ||
} |