Fix Relay SELECT with a non-integer database and add Relay range test (#1751)

Relay::select() throws a TypeError for anything but an integer, where
other connections get an error response from the server. Wrap the call
and return the same error response, so the existing test runs against
Relay and no longer needs a Relay-only counterpart.

Relay warns before sending SELECT for out-of-range databases, so that
test keeps its Relay-specific counterpart.
This commit is contained in:
Till Krüss
2026-11-03 10:29:11 -07:00
committed by GitHub
parent e1d96a8e6b
commit 21deb140e8
4 changed files with 128 additions and 1 deletions
@@ -12,6 +12,7 @@
namespace Predis\Connection;
use ArgumentCountError;
use PHPUnit\Framework\MockObject\MockObject;
use Predis\Client;
use Predis\ClientException;
@@ -24,6 +25,7 @@ use PredisTestCase;
use ReflectionClass;
use Relay\Exception as RelayException;
use Relay\Relay;
use TypeError;
/**
* @group ext-relay
@@ -166,6 +168,72 @@ class RelayConnectionTest extends PredisTestCase
$this->assertTrue($response);
}
/**
* @group disconnected
* @return void
*/
public function testExecuteSelectOnClient(): void
{
$this->mockClient
->expects($this->once())
->method('isConnected')
->withAnyParameters()
->willReturn(true);
$this->mockClient
->expects($this->once())
->method('SELECT')
->with(1)
->willReturn(true);
$response = $this->connection->executeCommand(new RawCommand('SELECT', [1]));
$this->assertTrue($response);
}
/**
* @group disconnected
* @return void
*/
public function testExecuteSelectReturnsErrorResponseOnNonIntegerDatabase(): void
{
$this->mockClient
->expects($this->once())
->method('isConnected')
->withAnyParameters()
->willReturn(true);
$this->mockClient
->method('SELECT')
->willThrowException(new TypeError('Argument #1 ($db) must be of type int, string given'));
$response = $this->connection->executeCommand(new RawCommand('SELECT', ['x']));
$this->assertInstanceOf(ErrorResponse::class, $response);
$this->assertSame('ERR value is not an integer or out of range', (string) $response);
}
/**
* @group disconnected
* @return void
*/
public function testExecuteSelectDoesNotHideArgumentCountError(): void
{
$this->mockClient
->expects($this->once())
->method('isConnected')
->withAnyParameters()
->willReturn(true);
$this->mockClient
->method('SELECT')
->willThrowException(new ArgumentCountError('Too few arguments'));
$this->expectException(ArgumentCountError::class);
$this->connection->executeCommand(new RawCommand('SELECT', []));
}
/**
* @group disconnected
* @return void