Skip to content

Commit

Permalink
qa: rename nodename to name
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilian Bösing <[email protected]>
  • Loading branch information
boesing committed May 24, 2021
1 parent f5bb3ec commit 26b5f64
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ jobs:
job: ${{ matrix.job }}
env:
TESTS_LAMINAS_CACHE_REDIS_HOST: redis
TESTS_LAMINAS_CACHE_REDIS_CLUSTER_NODENAME: cluster
TESTS_LAMINAS_CACHE_REDIS_CLUSTER_NAME: cluster
6 changes: 3 additions & 3 deletions src/Exception/InvalidRedisClusterConfigurationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public static function fromMissingSeedsForNamedConfiguration(string $name): self

public static function fromMissingRequiredValues(): self
{
return new self('Missing either `nodename` or `seeds`.');
return new self('Missing either `name` or `seeds`.');
}

public static function nodenameAndSeedsProvided(): self
public static function fromNameAndSeedsProvidedViaConfiguration(): self
{
return new self('Please provide either `nodename` or `seeds` configuration, not both.');
return new self('Please provide either `name` or `seeds` configuration, not both.');
}

public static function fromInvalidSeedsConfiguration(string $seed): self
Expand Down
29 changes: 16 additions & 13 deletions src/RedisClusterOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class RedisClusterOptions extends AdapterOptions
protected $namespaceSeparator = ':';

/** @var string */
private $nodename = '';
private $name = '';

/** @var float */
private $timeout = 1.0;
Expand Down Expand Up @@ -48,15 +48,15 @@ public function __construct($options = null)

/** @psalm-suppress InvalidArgument */
parent::__construct($options);
$hasNodename = $this->hasNodename();
$hasSeeds = $this->seeds() !== [];
$hasName = $this->hasName();
$hasSeeds = $this->seeds() !== [];

if (! $hasNodename && ! $hasSeeds) {
if (! $hasName && ! $hasSeeds) {
throw InvalidRedisClusterConfigurationException::fromMissingRequiredValues();
}

if ($hasNodename && $hasSeeds) {
throw InvalidRedisClusterConfigurationException::nodenameAndSeedsProvided();
if ($hasName && $hasSeeds) {
throw InvalidRedisClusterConfigurationException::fromNameAndSeedsProvidedViaConfiguration();
}
}

Expand Down Expand Up @@ -92,20 +92,23 @@ public function setNamespaceSeparator(string $namespaceSeparator): void
$this->namespaceSeparator = $namespaceSeparator;
}

public function hasNodename(): bool
public function hasName(): bool
{
return $this->nodename !== '';
return $this->name !== '';
}

public function nodename(): string
public function getName(): string
{
return $this->nodename;
return $this->name;
}

public function setNodename(string $nodename): void
/**
* @psalm-param non-empty-string $name
*/
public function setName(string $name): void
{
$this->nodename = $nodename;
$this->triggerOptionEvent('nodename', $nodename);
$this->name = $name;
$this->triggerOptionEvent('name', $name);
}

public function timeout(): float
Expand Down
56 changes: 28 additions & 28 deletions src/RedisClusterOptionsFromIni.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
final class RedisClusterOptionsFromIni
{
/** @psalm-var array<non-empty-string,list<non-empty-string>> */
private $seedsByNodename;
private $seedsByName;

/** @psalm-var array<non-empty-string,float> */
private $timeoutByNodename;
private $timeoutByName;

/** @psalm-var array<non-empty-string,float> */
private $readTimeoutByNodename;
private $readTimeoutByName;

public function __construct()
{
Expand All @@ -37,62 +37,62 @@ public function __construct()
throw InvalidRedisClusterConfigurationException::fromMissingSeedsConfiguration();
}

$seedsByNodename = [];
parse_str($seedsConfiguration, $seedsByNodename);
/** @psalm-var non-empty-array<non-empty-string,list<non-empty-string>> $seedsByNodename */
$this->seedsByNodename = $seedsByNodename;
$seedsByName = [];
parse_str($seedsConfiguration, $seedsByName);
/** @psalm-var non-empty-array<non-empty-string,list<non-empty-string>> $seedsByName */
$this->seedsByName = $seedsByName;

$timeoutConfiguration = ini_get('redis.clusters.timeout');
if (! is_string($timeoutConfiguration)) {
$timeoutConfiguration = '';
}

$timeoutByNodename = [];
parse_str($timeoutConfiguration, $timeoutByNodename);
foreach ($timeoutByNodename as $nodename => $timeout) {
assert($nodename !== '' && is_numeric($timeout));
$timeoutByNodename[$nodename] = (float) $timeout;
$timeoutByName = [];
parse_str($timeoutConfiguration, $timeoutByName);
foreach ($timeoutByName as $name => $timeout) {
assert($name !== '' && is_numeric($timeout));
$timeoutByName[$name] = (float) $timeout;
}
/** @psalm-var array<non-empty-string,float> $timeoutByNodename */
$this->timeoutByNodename = $timeoutByNodename;
/** @psalm-var array<non-empty-string,float> $timeoutByName */
$this->timeoutByName = $timeoutByName;

$readTimeoutConfiguration = ini_get('redis.clusters.read_timeout');
if (! is_string($readTimeoutConfiguration)) {
$readTimeoutConfiguration = '';
}

$readTimeoutByNodename = [];
parse_str($readTimeoutConfiguration, $readTimeoutByNodename);
foreach ($readTimeoutByNodename as $nodename => $readTimeout) {
assert($nodename !== '' && is_numeric($readTimeout));
$readTimeoutByNodename[$nodename] = (float) $readTimeout;
$readTimeoutByName = [];
parse_str($readTimeoutConfiguration, $readTimeoutByName);
foreach ($readTimeoutByName as $name => $readTimeout) {
assert($name !== '' && is_numeric($readTimeout));
$readTimeoutByName[$name] = (float) $readTimeout;
}

/** @psalm-var array<non-empty-string,float> $readTimeoutByNodename */
$this->readTimeoutByNodename = $readTimeoutByNodename;
/** @psalm-var array<non-empty-string,float> $readTimeoutByName */
$this->readTimeoutByName = $readTimeoutByName;
}

/**
* @return array<int,string>
* @psalm-return list<non-empty-string>
*/
public function seeds(string $nodename): array
public function seeds(string $name): array
{
$seeds = $this->seedsByNodename[$nodename] ?? [];
$seeds = $this->seedsByName[$name] ?? [];
if (! $seeds) {
throw InvalidRedisClusterConfigurationException::fromMissingSeedsForNamedConfiguration($nodename);
throw InvalidRedisClusterConfigurationException::fromMissingSeedsForNamedConfiguration($name);
}

return $seeds;
}

public function timeout(string $nodename, float $fallback): float
public function timeout(string $name, float $fallback): float
{
return $this->timeoutByNodename[$nodename] ?? $fallback;
return $this->timeoutByName[$name] ?? $fallback;
}

public function readTimeout(string $nodename, float $fallback): float
public function readTimeout(string $name, float $fallback): float
{
return $this->readTimeoutByNodename[$nodename] ?? $fallback;
return $this->readTimeoutByName[$name] ?? $fallback;
}
}
22 changes: 11 additions & 11 deletions src/RedisClusterResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public function getResource(): RedisClusterFromExtension

private function createRedisResource(RedisClusterOptions $options): RedisClusterFromExtension
{
if ($options->hasNodename()) {
return $this->createRedisResourceFromNodename(
$options->nodename(),
if ($options->hasName()) {
return $this->createRedisResourceFromName(
$options->getName(),
$options->timeout(),
$options->readTimeout(),
$options->persistent()
Expand All @@ -128,16 +128,16 @@ private function createRedisResource(RedisClusterOptions $options): RedisCluster
);
}

private function createRedisResourceFromNodename(
string $nodename,
private function createRedisResourceFromName(
string $name,
float $fallbackTimeout,
float $fallbackReadTimeout,
bool $persistent
): RedisClusterFromExtension {
$options = new RedisClusterOptionsFromIni();
$seeds = $options->seeds($nodename);
$timeout = $options->timeout($nodename, $fallbackTimeout);
$readTimeout = $options->readTimeout($nodename, $fallbackReadTimeout);
$seeds = $options->seeds($name);
$timeout = $options->timeout($name, $fallbackTimeout);
$readTimeout = $options->readTimeout($name, $fallbackReadTimeout);

return new RedisClusterFromExtension(null, $seeds, $timeout, $readTimeout, $persistent);
}
Expand Down Expand Up @@ -222,11 +222,11 @@ public function hasSerializationSupport(PluginCapableInterface $adapter): bool
*/
private function info(RedisClusterFromExtension $resource): array
{
$nodename = $this->options->nodename();
if ($this->options->hasName()) {
$name = $this->options->getName();

if ($nodename !== '') {
/** @psalm-var RedisClusterInfoType $info */
$info = $resource->info($nodename);
$info = $resource->info($name);
return $info;
}

Expand Down
6 changes: 3 additions & 3 deletions test/integration/Laminas/RedisClusterStorageCreationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ private function createRedisClusterStorage(int $serializerOption, bool $serializ
return $this->storage;
}

$node = $this->nodename();
$node = $this->getClusterNameFromEnvironment();

if ($node === '') {
throw new RuntimeException('Could not find nodename environment configuration.');
throw new RuntimeException('Could not find named config environment configuration.');
}

$this->options = new RedisClusterOptions([
'nodename' => $node,
'name' => $node,
'lib_options' => [
RedisClusterFromExtension::OPT_SERIALIZER => $serializerOption,
],
Expand Down
5 changes: 3 additions & 2 deletions test/integration/Laminas/RedisClusterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ public function testWillProperlyFlush(): void

public function testCanCreateResourceFromSeeds(): void
{
$nodename = $this->nodename();
$name = $this->getClusterNameFromEnvironment();
self::assertNotEmpty($name, 'Missing cluster name environment configuration.');
$optionsFromIni = new RedisClusterOptionsFromIni();
$options = new RedisClusterOptions([
'seeds' => $optionsFromIni->seeds($nodename),
'seeds' => $optionsFromIni->seeds($name),
]);

$storage = new RedisCluster($options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ private function password(): string
return $password;
}

private function nodename(): string
private function getClusterNameFromEnvironment(): string
{
$nodename = getenv('TESTS_LAMINAS_CACHE_REDIS_CLUSTER_NODENAME');
if ($nodename === false) {
$name = getenv('TESTS_LAMINAS_CACHE_REDIS_CLUSTER_NAME');
if ($name === false) {
return '';
}

return $nodename;
return $name;
}
}
11 changes: 6 additions & 5 deletions test/unit/RedisClusterOptionsFromIniTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ public function testWillThrowExceptionOnMissingSeedsConfiguration(): void
}

/**
* @dataProvider seedsByNodenameProvider
* @psalm-param non-empty-string $name
* @dataProvider seedsByNameProvider
*/
public function testWillDetectSeedsByNodename(string $nodename, string $config, array $expected): void
public function testWillDetectSeedsByName(string $name, string $config, array $expected): void
{
ini_set('redis.clusters.seeds', $config);
$options = new RedisClusterOptionsFromIni();
$seeds = $options->seeds($nodename);
$seeds = $options->getSeeds($name);
$this->assertEquals($expected, $seeds);
}

public function testWillThrowExceptionOnMissingNodenameInSeeds(): void
public function testWillThrowExceptionOnMissingNameInSeeds(): void
{
ini_set('redis.clusters.seeds', 'foo[]=bar:123');
$options = new RedisClusterOptionsFromIni();
Expand All @@ -44,7 +45,7 @@ public function testWillThrowExceptionOnMissingNodenameInSeeds(): void
/**
* @psalm-return non-empty-array<non-empty-string,array{0:non-empty-string,1:non-empty-string,2:non-empty-list<non-empty-string>}>
*/
public function seedsByNodenameProvider(): array
public function seedsByNameProvider(): array
{
return [
'simple' => [
Expand Down
12 changes: 6 additions & 6 deletions test/unit/RedisClusterOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ final class RedisClusterOptionsTest extends TestCase
public function testCanHandleOptionsWithNodename(): void
{
$options = new RedisClusterOptions([
'nodename' => 'foo',
'name' => 'foo',
'timeout' => 1.0,
'read_timeout' => 2.0,
'persistent' => false,
'redis_version' => '1.0',
]);

$this->assertEquals($options->nodename(), 'foo');
$this->assertEquals($options->getName(), 'foo');
$this->assertEquals($options->timeout(), 1.0);
$this->assertEquals($options->readTimeout(), 2.0);
$this->assertEquals($options->persistent(), false);
Expand All @@ -48,10 +48,10 @@ public function testCanHandleOptionsWithSeeds(): void
public function testWillDetectSeedsAndNodenameConfiguration(): void
{
$this->expectException(InvalidRedisClusterConfigurationException::class);
$this->expectExceptionMessage('Please provide either `nodename` or `seeds` configuration, not both.');
$this->expectExceptionMessage('Please provide either `name` or `seeds` configuration, not both.');
new RedisClusterOptions([
'seeds' => ['localhost:1234'],
'nodename' => 'foo',
'seeds' => ['localhost:1234'],
'name' => 'foo',
]);
}

Expand All @@ -74,7 +74,7 @@ public function testWillValidateEmptyVersion(): void
public function testWillDetectMissingRequiredValues(): void
{
$this->expectException(InvalidRedisClusterConfigurationException::class);
$this->expectExceptionMessage('Missing either `nodename` or `seeds`.');
$this->expectExceptionMessage('Missing either `name` or `seeds`.');
new RedisClusterOptions();
}
}
8 changes: 4 additions & 4 deletions test/unit/RedisClusterResourceManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testCanDetectSerializationSupportFromSerializerPlugin(): void
->willReturn(true);

$manager = new RedisClusterResourceManager(new RedisClusterOptions([
'nodename' => uniqid('', true),
'name' => uniqid('', true),
]));
$adapter = $this->createMock(AbstractAdapter::class);
$adapter
Expand All @@ -58,7 +58,7 @@ public function testCanDetectSerializationSupportFromSerializerPlugin(): void
public function testWillReturnVersionFromOptions(): void
{
$manager = new RedisClusterResourceManager(new RedisClusterOptions([
'nodename' => uniqid('', true),
'name' => uniqid('', true),
'redis_version' => '1.0.0',
]));

Expand All @@ -74,15 +74,15 @@ public function serializationSupportOptionsProvider(): array
return [
'php-serialize' => [
new RedisClusterOptions([
'nodename' => uniqid('', true),
'name' => uniqid('', true),
'lib_options' => [
RedisCluster::OPT_SERIALIZER => RedisCluster::SERIALIZER_PHP,
],
]),
],
'igbinary-serialize' => [
new RedisClusterOptions([
'nodename' => uniqid('', true),
'name' => uniqid('', true),
'lib_options' => [
RedisCluster::OPT_SERIALIZER => RedisCluster::SERIALIZER_IGBINARY,
],
Expand Down
Loading

0 comments on commit 26b5f64

Please sign in to comment.