Skip to content

Commit

Permalink
Merge pull request #81 from acelaya-forks/feature/geolite-license
Browse files Browse the repository at this point in the history
Feature/geolite license
  • Loading branch information
acelaya authored Apr 29, 2020
2 parents c2c9881 + daf962e commit 4232239
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).

## 4.4.0 - 2020-04-29

#### Added

* [#80](https://github.com/shlinkio/shlink-installer/issues/80) Added config option to ask for a custom GeoLite license key.

#### Changed

* *Nothing*

#### Deprecated

* *Nothing*

#### Removed

* *Nothing*

#### Fixed

* *Nothing*


## 4.3.2 - 2020-04-06

#### Added
Expand Down
2 changes: 2 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
Config\Option\ValidateUrlConfigOption::class,
Config\Option\VisitsWebhooksConfigOption::class,
Config\Option\ShortCodeLengthOption::class,
Config\Option\GeoLiteLicenseKeyConfigOption::class,
],
'REDIRECTS' => [
Config\Option\BaseUrlRedirectConfigOption::class,
Expand Down Expand Up @@ -85,6 +86,7 @@
Config\Option\TaskWorkerNumConfigOption::class => ConfigAbstractFactory::class,
Config\Option\WebWorkerNumConfigOption::class => ConfigAbstractFactory::class,
Config\Option\ShortCodeLengthOption::class => InvokableFactory::class,
Config\Option\GeoLiteLicenseKeyConfigOption::class => InvokableFactory::class,
],
],

Expand Down
26 changes: 26 additions & 0 deletions src/Config/Option/GeoLiteLicenseKeyConfigOption.php
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';
}
}
51 changes: 51 additions & 0 deletions test/Config/Option/GeoLiteLicenseKeyConfigOptionTest.php
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'];
}
}

0 comments on commit 4232239

Please sign in to comment.