2
2
3
3
namespace LaunchDarkly \Impl \Integrations \Tests \Impl \Integrations ;
4
4
5
- use Exception ;
6
5
use LaunchDarkly \Impl \Integrations \PHPRedisBigSegmentsStore ;
7
6
use PHPUnit \Framework ;
8
7
use Psr \Log ;
@@ -15,32 +14,27 @@ public function testGetMetadata(): void
15
14
$ now = time ();
16
15
$ logger = new Log \NullLogger ();
17
16
18
- $ connection = $ this ->createMock (Redis::class);
17
+ $ connection = new Redis ();
18
+ $ connection ->flushAll ();
19
19
$ store = new PHPRedisBigSegmentsStore ($ connection , $ logger , []);
20
20
21
- $ connection ->expects ($ this ->once ())
22
- ->method ('get ' )
23
- ->with ('launchdarkly:big_segments_synchronized_on ' )
24
- ->willReturn ("$ now " );
25
-
26
21
$ metadata = $ store ->getMetadata ();
22
+ $ this ->assertNull ($ metadata ->getLastUpToDate ());
23
+ $ this ->assertTrue ($ metadata ->isStale (10 ));
27
24
25
+ $ connection ->set ('launchdarkly:big_segments_synchronized_on ' , $ now );
26
+ $ metadata = $ store ->getMetadata ();
28
27
$ this ->assertEquals ($ now , $ metadata ->getLastUpToDate ());
29
28
$ this ->assertFalse ($ metadata ->isStale (10 ));
30
29
}
31
30
32
- public function testGetMetadataWithException (): void
31
+ public function testGetMetadataWithInvalidConfiguration (): void
33
32
{
34
33
$ logger = new Log \NullLogger ();
35
34
36
- $ connection = $ this -> createMock ( Redis::class );
35
+ $ connection = new Redis ([ ' port ' => 33_333 , ' connectTimeout ' => 1 ] );
37
36
$ store = new PHPRedisBigSegmentsStore ($ connection , $ logger , []);
38
37
39
- $ connection ->expects ($ this ->once ())
40
- ->method ('get ' )
41
- ->with ('launchdarkly:big_segments_synchronized_on ' )
42
- ->willThrowException (new \Exception ('sorry ' ));
43
-
44
38
$ metadata = $ store ->getMetadata ();
45
39
46
40
$ this ->assertNull ($ metadata ->getLastUpToDate ());
@@ -51,18 +45,12 @@ public function testCanDetectInclusion(): void
51
45
{
52
46
$ logger = new Log \NullLogger ();
53
47
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 ' );
56
52
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 , []);
66
54
67
55
$ membership = $ store ->getMembership ('ctx ' ) ?? [];
68
56
@@ -72,23 +60,27 @@ public function testCanDetectInclusion(): void
72
60
$ this ->assertFalse ($ membership ['key3 ' ]);
73
61
}
74
62
75
- public function testCanDetectInclusionWithException (): void
63
+ public function testCanDetectInclusionWithEmptyData (): void
76
64
{
77
65
$ logger = new Log \NullLogger ();
78
66
79
- $ connection = $ this ->createMock (Redis::class);
67
+ $ connection = new Redis ();
68
+ $ connection ->flushAll ();
69
+
80
70
$ store = new PHPRedisBigSegmentsStore ($ connection , $ logger , []);
81
71
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
+ }
91
77
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 , []);
92
84
$ membership = $ store ->getMembership ('ctx ' );
93
85
94
86
$ this ->assertNull ($ membership );
0 commit comments