Skip to content
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
2 changes: 1 addition & 1 deletion src/RedisClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public function __construct(string $uri, ?ConnectorInterface $connector = null)
$parts = parse_url($uri);
}

$uri = (string) preg_replace(['/(:)[^:\/]*(@)/', '/([?&]password=).*?($|&)/'], '$1***$2', $uri);
if ($parts === false || !isset($parts['scheme'], $parts['host']) || !in_array($parts['scheme'], ['redis', 'rediss', 'redis+unix'])) {
$uri = (string) preg_replace(['/(:)[^:\/]*(@)/', '/([?&]password=).*?($|&)/'], '$1***$2', $uri);
throw new \InvalidArgumentException(
'Invalid Redis URI "' . $uri . '" (EINVAL)',
defined('SOCKET_EINVAL') ? SOCKET_EINVAL : 22
Expand Down
22 changes: 21 additions & 1 deletion tests/RedisClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,27 @@ public function testCtorWithInvalidUriThrows(string $uri, string $message): void
public function testPingWillCreateUnderlyingClientAndReturnPendingPromise(): void
{
$promise = new Promise(function () { });
$this->factory->expects($this->once())->method('createClient')->willReturn($promise);
$this->factory->expects($this->once())->method('createClient')->with('redis://localhost')->willReturn($promise);

$loop = $this->createMock(LoopInterface::class);
$loop->expects($this->never())->method('addTimer');
assert($loop instanceof LoopInterface);
Loop::set($loop);

$promise = $this->redis->ping();

$promise->then($this->expectCallableNever());
}

public function testPingWithAuthWillCreateUnderlyingClientWithAuthAndReturnPendingPromise(): void
{
$this->redis = new RedisClient('user:pass@localhost');
$ref = new \ReflectionProperty($this->redis, 'factory');
$ref->setAccessible(true);
$ref->setValue($this->redis, $this->factory);

$promise = new Promise(function () { });
$this->factory->expects($this->once())->method('createClient')->with('redis://user:pass@localhost')->willReturn($promise);

$loop = $this->createMock(LoopInterface::class);
$loop->expects($this->never())->method('addTimer');
Expand Down