From 65d8b4d8a9dee7734db0490137d146eff8182f2d Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Wed, 31 Jul 2024 07:58:53 +0530 Subject: [PATCH] Fix unable to configure redis socket with port 0, #PG-3714 --- SystemSettings.php | 4 ++-- tests/Integration/SettingsTest.php | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/SystemSettings.php b/SystemSettings.php index 38daf50..e3be9ba 100644 --- a/SystemSettings.php +++ b/SystemSettings.php @@ -151,11 +151,11 @@ private function createRedisPortSetting() $self->checkMultipleServersOnlyConfiguredWhenSentinelIsEnabled($value); if (!$self->isUsingSentinelBackend()) { - (new NumberRange(1, 65535))->validate($value); + (new NumberRange(0, 65535))->validate($value); } else { $ports = explode(',', $value); foreach ($ports as $port) { - (new NumberRange(1, 65535))->validate(trim($port)); + (new NumberRange(0, 65535))->validate(trim($port)); } } }; diff --git a/tests/Integration/SettingsTest.php b/tests/Integration/SettingsTest.php index 66d08c2..0cb0d27 100644 --- a/tests/Integration/SettingsTest.php +++ b/tests/Integration/SettingsTest.php @@ -50,9 +50,9 @@ public function test_redisHost_ShouldFail_IfMoreThan300CharctersGiven() public function test_redisPort_ShouldFail_IfPortIsTooLow() { $this->expectException(\Exception::class); - $this->expectExceptionMessage('The value needs to be at least 1'); + $this->expectExceptionMessage('The value needs to be at least 0'); - $this->settings->redisPort->setValue(0); + $this->settings->redisPort->setValue(-1); } public function test_redisPort_ShouldFail_IfPortIsTooHigh() @@ -63,6 +63,12 @@ public function test_redisPort_ShouldFail_IfPortIsTooHigh() $this->settings->redisPort->setValue(65536); } + public function test_redisPort_ShouldNotFail_IfPortIsZero() + { + $this->settings->redisPort->setValue(0); + $this->assertEquals(0, $this->settings->redisPort->getValue()); + } + public function test_redisTimeout_ShouldFail_IfTooLong() { $this->expectException(\Exception::class); @@ -250,8 +256,8 @@ public function test_redisPort_ShouldFailWhenMultipleValuesGiven_IfSentinelNotEn public function test_redisPort_ShouldNotFailAndConvertToIntWhenMultipleValuesGiven_IfSentinelIsEnabled() { $this->enableRedisSentinel(); - $this->settings->redisPort->setValue('55 , 44.34 '); - $this->assertSame('55,44', $this->settings->redisPort->getValue()); + $this->settings->redisPort->setValue('55 , 44.34, 0 '); + $this->assertSame('55,44,0', $this->settings->redisPort->getValue()); } public function test_redisPort_ShouldValidateEachPortSeparately_WhenManySpecified() @@ -260,7 +266,7 @@ public function test_redisPort_ShouldValidateEachPortSeparately_WhenManySpecifie $this->expectExceptionMessage('The value is not a number'); $this->enableRedisSentinel(); - $this->settings->redisPort->setValue('55 , 44.34, 4mk '); + $this->settings->redisPort->setValue('55, 0 , 44.34, 4mk '); $this->assertSame('55,44', $this->settings->redisPort->getValue()); }