Skip to content

Commit 6fe7133

Browse files
committed
temp
1 parent 61cae59 commit 6fe7133

File tree

1 file changed

+28
-36
lines changed

1 file changed

+28
-36
lines changed

tests/Impl/Integrations/PHPRedisBigSegmentsStoreTest.php

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace LaunchDarkly\Impl\Integrations\Tests\Impl\Integrations;
44

5-
use Exception;
65
use LaunchDarkly\Impl\Integrations\PHPRedisBigSegmentsStore;
76
use PHPUnit\Framework;
87
use Psr\Log;
@@ -15,32 +14,27 @@ public function testGetMetadata(): void
1514
$now = time();
1615
$logger = new Log\NullLogger();
1716

18-
$connection = $this->createMock(Redis::class);
17+
$connection = new Redis();
18+
$connection->flushAll();
1919
$store = new PHPRedisBigSegmentsStore($connection, $logger, []);
2020

21-
$connection->expects($this->once())
22-
->method('get')
23-
->with('launchdarkly:big_segments_synchronized_on')
24-
->willReturn("$now");
25-
2621
$metadata = $store->getMetadata();
22+
$this->assertNull($metadata->getLastUpToDate());
23+
$this->assertTrue($metadata->isStale(10));
2724

25+
$connection->set('launchdarkly:big_segments_synchronized_on', $now);
26+
$metadata = $store->getMetadata();
2827
$this->assertEquals($now, $metadata->getLastUpToDate());
2928
$this->assertFalse($metadata->isStale(10));
3029
}
3130

32-
public function testGetMetadataWithException(): void
31+
public function testGetMetadataWithInvalidConfiguration(): void
3332
{
3433
$logger = new Log\NullLogger();
3534

36-
$connection = $this->createMock(Redis::class);
35+
$connection = new Redis(['port' => 33_333, 'connectTimeout' => 1]);
3736
$store = new PHPRedisBigSegmentsStore($connection, $logger, []);
3837

39-
$connection->expects($this->once())
40-
->method('get')
41-
->with('launchdarkly:big_segments_synchronized_on')
42-
->willThrowException(new \Exception('sorry'));
43-
4438
$metadata = $store->getMetadata();
4539

4640
$this->assertNull($metadata->getLastUpToDate());
@@ -51,18 +45,12 @@ public function testCanDetectInclusion(): void
5145
{
5246
$logger = new Log\NullLogger();
5347

54-
$connection = $this->createMock(Redis::class);
55-
$store = new PHPRedisBigSegmentsStore($connection, $logger, []);
48+
$connection = new Redis();
49+
$connection->flushAll();
50+
$connection->sAdd('launchdarkly:big_segment_include:ctx', 'key1', 'key2');
51+
$connection->sAdd('launchdarkly:big_segment_exclude:ctx', 'key1', 'key3');
5652

57-
$connection->expects($this->exactly(2))
58-
->method('sMembers')
59-
->willReturnCallback(function (string $key) {
60-
return match ($key) {
61-
'launchdarkly:big_segment_include:ctx' => ['key1', 'key2'],
62-
'launchdarkly:big_segment_exclude:ctx' => ['key1', 'key3'],
63-
default => [],
64-
};
65-
});
53+
$store = new PHPRedisBigSegmentsStore($connection, $logger, []);
6654

6755
$membership = $store->getMembership('ctx') ?? [];
6856

@@ -72,23 +60,27 @@ public function testCanDetectInclusion(): void
7260
$this->assertFalse($membership['key3']);
7361
}
7462

75-
public function testCanDetectInclusionWithException(): void
63+
public function testCanDetectInclusionWithEmptyData(): void
7664
{
7765
$logger = new Log\NullLogger();
7866

79-
$connection = $this->createMock(Redis::class);
67+
$connection = new Redis();
68+
$connection->flushAll();
69+
8070
$store = new PHPRedisBigSegmentsStore($connection, $logger, []);
8171

82-
$connection->expects($this->exactly(2))
83-
->method('sMembers')
84-
->willReturnCallback(function (string $key) {
85-
return match ($key) {
86-
'launchdarkly:big_segment_include:ctx' => ['key1', 'key2'],
87-
'launchdarkly:big_segment_exclude:ctx' => throw new Exception('sorry'),
88-
default => [],
89-
};
90-
});
72+
$membership = $store->getMembership('ctx');
73+
74+
$this->assertNotNull($membership);
75+
$this->assertCount(0, $membership);
76+
}
9177

78+
public function testCanDetectInclusionWithInvalidConfiguration(): void
79+
{
80+
$logger = new Log\NullLogger();
81+
82+
$connection = new Redis(['port' => 33_333, 'connectTimeout' => 1]);
83+
$store = new PHPRedisBigSegmentsStore($connection, $logger, []);
9284
$membership = $store->getMembership('ctx');
9385

9486
$this->assertNull($membership);

0 commit comments

Comments
 (0)