Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/Prometheus/Storage/RedisClients/Predis.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public function setNx(string $key, mixed $value): void

public function sMembers(string $key): array
{
return $this->client->smembers($key);
/** @phpstan-ignore-next-line Predis can return null at runtime despite its array return type. */
return $this->client->smembers($key) ?? [];
}

public function hGetAll(string $key): array|false
Expand Down
20 changes: 20 additions & 0 deletions tests/Test/Prometheus/Storage/PredisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,24 @@ public function itShouldNotClearWholeRedisOnFlush(): void
self::equalTo(['not a prometheus metric key'])
);
}

/**
* @test
*/
public function itShouldReturnAnEmptyArrayWhenSMembersReturnsNull(): void
{
$client = $this->getMockBuilder(Client::class)
->disableOriginalConstructor()
->addMethods(['smembers'])
->getMock();

$client->expects(self::once())
->method('smembers')
->with('missing-key')
->willReturn(null);

$predis = new \Prometheus\Storage\RedisClients\Predis($client);

self::assertSame([], $predis->sMembers('missing-key'));
}
}
Loading