-
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 #202 from acelaya-forks/feature/matomo-support
Feature/matomo support
- Loading branch information
Showing
12 changed files
with
291 additions
and
3 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
20 changes: 20 additions & 0 deletions
20
src/Config/Option/Matomo/AbstractMatomoEnabledConfigOption.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,20 @@ | ||
<?php | ||
|
||
namespace Shlinkio\Shlink\Installer\Config\Option\Matomo; | ||
|
||
use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption; | ||
use Shlinkio\Shlink\Installer\Config\Option\DependentConfigOptionInterface; | ||
|
||
abstract class AbstractMatomoEnabledConfigOption extends BaseConfigOption implements DependentConfigOptionInterface | ||
{ | ||
public function shouldBeAsked(array $currentOptions): bool | ||
{ | ||
$matomoEnabled = $currentOptions[MatomoEnabledConfigOption::ENV_VAR] ?? false; | ||
return $matomoEnabled && parent::shouldBeAsked($currentOptions); | ||
} | ||
|
||
public function getDependentOption(): string | ||
{ | ||
return MatomoEnabledConfigOption::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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Shlinkio\Shlink\Installer\Config\Option\Matomo; | ||
|
||
use Shlinkio\Shlink\Installer\Util\AskUtilsTrait; | ||
use Symfony\Component\Console\Style\StyleInterface; | ||
|
||
class MatomoApiTokenConfigOption extends AbstractMatomoEnabledConfigOption | ||
{ | ||
use AskUtilsTrait; | ||
|
||
public function getEnvVar(): string | ||
{ | ||
return 'MATOMO_API_TOKEN'; | ||
} | ||
|
||
public function ask(StyleInterface $io, array $currentOptions): string | ||
{ | ||
return $this->askRequired($io, 'Matomo API token'); | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Shlinkio\Shlink\Installer\Config\Option\Matomo; | ||
|
||
use Shlinkio\Shlink\Installer\Util\AskUtilsTrait; | ||
use Symfony\Component\Console\Style\StyleInterface; | ||
|
||
class MatomoBaseUrlConfigOption extends AbstractMatomoEnabledConfigOption | ||
{ | ||
use AskUtilsTrait; | ||
|
||
public function getEnvVar(): string | ||
{ | ||
return 'MATOMO_BASE_URL'; | ||
} | ||
|
||
public function ask(StyleInterface $io, array $currentOptions): string | ||
{ | ||
return $this->askRequired($io, 'Matomo server URL'); | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Shlinkio\Shlink\Installer\Config\Option\Matomo; | ||
|
||
use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption; | ||
use Symfony\Component\Console\Style\StyleInterface; | ||
|
||
class MatomoEnabledConfigOption extends BaseConfigOption | ||
{ | ||
public const ENV_VAR = 'MATOMO_ENABLED'; | ||
|
||
public function getEnvVar(): string | ||
{ | ||
return self::ENV_VAR; | ||
} | ||
|
||
public function ask(StyleInterface $io, array $currentOptions): bool | ||
{ | ||
return $io->confirm('Do you want Shlink to send all visits to an external Matomo server?', false); | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Shlinkio\Shlink\Installer\Config\Option\Matomo; | ||
|
||
use Shlinkio\Shlink\Installer\Util\AskUtilsTrait; | ||
use Symfony\Component\Console\Style\StyleInterface; | ||
|
||
class MatomoSiteIdConfigOption extends AbstractMatomoEnabledConfigOption | ||
{ | ||
use AskUtilsTrait; | ||
|
||
public function getEnvVar(): string | ||
{ | ||
return 'MATOMO_SITE_ID'; | ||
} | ||
|
||
public function ask(StyleInterface $io, array $currentOptions): string | ||
{ | ||
return $this->askRequired($io, 'Matomo site ID'); | ||
} | ||
} |
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
test/Config/Option/Matomo/MatomoApiTokenConfigOptionTest.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 ShlinkioTest\Shlink\Installer\Config\Option\Matomo; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
use Shlinkio\Shlink\Installer\Config\Option\Matomo\MatomoApiTokenConfigOption; | ||
use Symfony\Component\Console\Style\StyleInterface; | ||
|
||
class MatomoApiTokenConfigOptionTest extends TestCase | ||
{ | ||
private MatomoApiTokenConfigOption $configOption; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->configOption = new MatomoApiTokenConfigOption(); | ||
} | ||
|
||
#[Test] | ||
public function returnsExpectedEnvVar(): void | ||
{ | ||
self::assertEquals('MATOMO_API_TOKEN', $this->configOption->getEnvVar()); | ||
} | ||
|
||
#[Test] | ||
public function expectedQuestionIsAsked(): void | ||
{ | ||
$expectedAnswer = 'abc123'; | ||
$io = $this->createMock(StyleInterface::class); | ||
$io->expects($this->once())->method('ask')->with('Matomo API token')->willReturn($expectedAnswer); | ||
|
||
$answer = $this->configOption->ask($io, []); | ||
|
||
self::assertEquals($expectedAnswer, $answer); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
test/Config/Option/Matomo/MatomoBaseUrlConfigOptionTest.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,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ShlinkioTest\Shlink\Installer\Config\Option\Matomo; | ||
|
||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
use Shlinkio\Shlink\Installer\Config\Option\Matomo\MatomoBaseUrlConfigOption; | ||
use Shlinkio\Shlink\Installer\Config\Option\Matomo\MatomoEnabledConfigOption; | ||
use Symfony\Component\Console\Style\StyleInterface; | ||
|
||
class MatomoBaseUrlConfigOptionTest extends TestCase | ||
{ | ||
private MatomoBaseUrlConfigOption $configOption; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->configOption = new MatomoBaseUrlConfigOption(); | ||
} | ||
|
||
#[Test] | ||
public function returnsExpectedEnvVar(): void | ||
{ | ||
self::assertEquals('MATOMO_BASE_URL', $this->configOption->getEnvVar()); | ||
} | ||
|
||
#[Test] | ||
public function expectedQuestionIsAsked(): void | ||
{ | ||
$expectedAnswer = 'foobar.com'; | ||
$io = $this->createMock(StyleInterface::class); | ||
$io->expects($this->once())->method('ask')->with('Matomo server URL')->willReturn($expectedAnswer); | ||
|
||
$answer = $this->configOption->ask($io, []); | ||
|
||
self::assertEquals($expectedAnswer, $answer); | ||
} | ||
|
||
#[Test] | ||
public function dependsOnMatomoEnabled(): void | ||
{ | ||
self::assertEquals(MatomoEnabledConfigOption::class, $this->configOption->getDependentOption()); | ||
} | ||
|
||
#[Test, DataProvider('provideCurrentOptions')] | ||
public function shouldBeAskedOnlyIfMatomoIsEnabled(array $currentOptions, bool $expected): void | ||
{ | ||
self::assertEquals($expected, $this->configOption->shouldBeAsked($currentOptions)); | ||
} | ||
|
||
public static function provideCurrentOptions(): iterable | ||
{ | ||
yield 'matomo enabled' => [[MatomoEnabledConfigOption::ENV_VAR => true], true]; | ||
yield 'matomo not enabled' => [[MatomoEnabledConfigOption::ENV_VAR => false], false]; | ||
yield 'matomo not set' => [[], false]; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
test/Config/Option/Matomo/MatomoEnabledConfigOptionTest.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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ShlinkioTest\Shlink\Installer\Config\Option\Matomo; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
use Shlinkio\Shlink\Installer\Config\Option\Matomo\MatomoEnabledConfigOption; | ||
use Symfony\Component\Console\Style\StyleInterface; | ||
|
||
class MatomoEnabledConfigOptionTest extends TestCase | ||
{ | ||
private MatomoEnabledConfigOption $configOption; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->configOption = new MatomoEnabledConfigOption(); | ||
} | ||
|
||
#[Test] | ||
public function returnsExpectedEnvVar(): void | ||
{ | ||
self::assertEquals('MATOMO_ENABLED', $this->configOption->getEnvVar()); | ||
} | ||
|
||
#[Test] | ||
public function expectedQuestionIsAsked(): void | ||
{ | ||
$io = $this->createMock(StyleInterface::class); | ||
$io->expects($this->once())->method('confirm')->with( | ||
'Do you want Shlink to send all visits to an external Matomo server?', | ||
false, | ||
)->willReturn(true); | ||
|
||
$answer = $this->configOption->ask($io, []); | ||
|
||
self::assertTrue($answer); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
test/Config/Option/Matomo/MatomoSiteIdConfigOptionTest.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 ShlinkioTest\Shlink\Installer\Config\Option\Matomo; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
use Shlinkio\Shlink\Installer\Config\Option\Matomo\MatomoSiteIdConfigOption; | ||
use Symfony\Component\Console\Style\StyleInterface; | ||
|
||
class MatomoSiteIdConfigOptionTest extends TestCase | ||
{ | ||
private MatomoSiteIdConfigOption $configOption; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->configOption = new MatomoSiteIdConfigOption(); | ||
} | ||
|
||
#[Test] | ||
public function returnsExpectedEnvVar(): void | ||
{ | ||
self::assertEquals('MATOMO_SITE_ID', $this->configOption->getEnvVar()); | ||
} | ||
|
||
#[Test] | ||
public function expectedQuestionIsAsked(): void | ||
{ | ||
$expectedAnswer = '12345'; | ||
$io = $this->createMock(StyleInterface::class); | ||
$io->expects($this->once())->method('ask')->with('Matomo site ID')->willReturn($expectedAnswer); | ||
|
||
$answer = $this->configOption->ask($io, []); | ||
|
||
self::assertEquals($expectedAnswer, $answer); | ||
} | ||
} |