getCommand(); $command->setArguments($arguments); $this->assertSame($expected, $command->getArguments()); } /** * @group disconnected */ public function testParseResponse(): void { $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** * @group connected */ public function testCanSelectDifferentDatabase(): void { $redis = $this->getClient(); $redis->set('foo', 'bar'); $this->assertEquals('OK', $redis->select(REDIS_SERVER_DBNUM + 1)); $this->assertSame(0, $redis->exists('foo')); } /** * @group connected * @group relay-incompatible */ public function testThrowsExceptionOnUnexpectedDatabaseRange(): void { $this->expectException('Predis\Response\ServerException'); $this->expectExceptionMessageMatches('/ERR.*DB index/'); $redis = $this->getClient(); $redis->select(100000000); } /** * Relay warns before sending SELECT for indexes beyond `relay.databases`, * which PHPUnit would turn into an exception before the server replies. * * @group connected */ public function testThrowsExceptionOnUnexpectedDatabaseRangeDespiteRelayWarning(): void { if (!getenv('USE_RELAY')) { $this->markTestSkipped('Relay only warns when it is the active connection.'); } $this->expectException('Predis\Response\ServerException'); $this->expectExceptionMessageMatches('/ERR.*DB index/'); $redis = $this->getClient(); $previous = set_error_handler( static function ($level, $message, $file = '', $line = 0) use (&$previous) { if (strpos($message, 'in-memory databases') !== false) { return true; } return $previous ? $previous($level, $message, $file, $line) : false; } ); try { $redis->select(100000000); } finally { restore_error_handler(); } } /** * @group connected */ public function testThrowsExceptionOnUnexpectedDatabaseName(): void { $this->expectException('Predis\Response\ServerException'); $this->expectExceptionMessageMatches('/ERR.*(invalid DB index|value is not an integer or out of range)/'); $redis = $this->getClient(); $redis->select('x'); } }