Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cache namespace option #197

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ 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).

## [Unreleased]
### Added
* Add `CacheNamespaceConfigOption` to customize the cache namespace.

### Changed
* *Nothing*

### Deprecated
* *Nothing*

### Removed
* *Nothing*

### Fixed
* *Nothing*


## [8.5.0] - 2023-09-22
### Added
* Improve `init` command's `--initial-api-key` flag, so that it can receive an optional value which will be used as the initial API key.
Expand Down
2 changes: 2 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
'Delete short URLs > Visits threshold' => Config\Option\Visit\VisitsThresholdConfigOption::class,
'Base path' => Config\Option\BasePathConfigOption::class,
'Timezone' => Config\Option\TimezoneConfigOption::class,
'Cache > namespace' => Config\Option\Cache\CacheNamespaceConfigOption::class,
'Swoole > Amount of task workers' => Config\Option\Worker\TaskWorkerNumConfigOption::class,
'Swoole > Amount of web workers' => Config\Option\Worker\WebWorkerNumConfigOption::class,
],
Expand All @@ -115,6 +116,7 @@
'factories' => [
Config\Option\BasePathConfigOption::class => InvokableFactory::class,
Config\Option\TimezoneConfigOption::class => InvokableFactory::class,
Config\Option\Cache\CacheNamespaceConfigOption::class => InvokableFactory::class,
Config\Option\Visit\VisitsThresholdConfigOption::class => InvokableFactory::class,
Config\Option\Database\DatabaseDriverConfigOption::class => InvokableFactory::class,
Config\Option\Database\DatabaseNameConfigOption::class => InvokableFactory::class,
Expand Down
25 changes: 25 additions & 0 deletions src/Config/Option/Cache/CacheNamespaceConfigOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Shlinkio\Shlink\Installer\Config\Option\Cache;

use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption;
use Symfony\Component\Console\Style\StyleInterface;

class CacheNamespaceConfigOption extends BaseConfigOption
{
public function getEnvVar(): string
{
return 'CACHE_NAMESPACE';
}

public function ask(StyleInterface $io, array $currentOptions): string
{
return $io->ask(
'Prefix for cache entry keys. (Change this if you run multiple Shlink instances on this server, or they '
. 'share the same redis instance)',
'Shlink',
);
}
}
41 changes: 41 additions & 0 deletions test/Config/Option/Cache/CacheNamespaceConfigOptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace ShlinkioTest\Shlink\Installer\Config\Option\Cache;

use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Installer\Config\Option\Cache\CacheNamespaceConfigOption;
use Symfony\Component\Console\Style\StyleInterface;

class CacheNamespaceConfigOptionTest extends TestCase
{
private CacheNamespaceConfigOption $configOption;

public function setUp(): void
{
$this->configOption = new CacheNamespaceConfigOption();
}

#[Test]
public function returnsExpectedEnvVar(): void
{
self::assertEquals('CACHE_NAMESPACE', $this->configOption->getEnvVar());
}

#[Test]
public function expectedQuestionIsAsked(): void
{
$io = $this->createMock(StyleInterface::class);
$io->expects($this->once())->method('ask')->with(
'Prefix for cache entry keys. (Change this if you run multiple Shlink instances on this server, or they '
. 'share the same redis instance)',
'Shlink',
)->willReturn('Shlink');

$answer = $this->configOption->ask($io, []);

self::assertEquals('Shlink', $answer);
}
}