11<?php
22
3- namespace BotMan \BotMan \Tests ;
3+ namespace BotMan \BotMan \Tests \ Cache \ RedisCache ;
44
55use BotMan \BotMan \Cache \ArrayCache ;
66use BotMan \BotMan \Cache \RedisCache ;
1010
1111/**
1212 * @group integration
13- * @group redis-auth
13+ * @group redis-secure
1414 */
15- class RedisCacheTest extends TestCase
15+ class SecureTest extends TestCase
1616{
1717 protected function setUp (): void
1818 {
@@ -25,29 +25,17 @@ protected function tearDown(): void
2525 {
2626 $ script = sprintf ("for i, name in ipairs(redis.call('KEYS', '%s*')) do redis.call('DEL', name); end " , RedisCache::KEY_PREFIX );
2727
28- if (! $ this ->isSecure ())
29- {
30- $ redis = new Redis ();
31- $ redis ->connect ($ this ->getRedisHost (), $ this ->getAuthRedisPort ());
32- $ redis ->eval ($ script );
33- $ redis ->close ();
34- } else {
35- $ redis = new Redis ();
36- $ redis ->connect ($ this ->getRedisHost (), $ this ->getAuthRedisPort ());
37- $ redis ->auth ('secret ' );
38- $ redis ->eval ($ script );
39- $ redis ->close ();
40- }
28+ $ redis = new Redis ();
29+ $ redis ->connect ($ this ->getRedisHost (), $ this ->getRedisPort ());
30+ $ redis ->auth ('secret ' );
31+ $ redis ->eval ($ script );
32+ $ redis ->close ();
4133 }
4234
4335 /** @test */
4436 public function valid_auth ()
4537 {
46- if (! $ this ->isSecure ()) {
47- $ this ->markTestSkipped ('This function needs a secure instance ' );
48- }
49-
50- $ cache = new RedisCache ($ this ->getRedisHost (), $ this ->getAuthRedisPort (), 'secret ' );
38+ $ cache = new RedisCache ($ this ->getRedisHost (), $ this ->getRedisPort (), 'secret ' );
5139 $ cache ->put ('foo ' , 'bar ' , 1 );
5240 static ::assertTrue ($ cache ->has ('foo ' ));
5341 }
@@ -58,45 +46,29 @@ public function valid_auth()
5846 */
5947 public function invalid_auth ()
6048 {
61- if (! $ this ->isSecure ()) {
62- $ this ->markTestSkipped ('This function needs a secure instance ' );
63- }
64-
65- $ cache = new RedisCache ($ this ->getRedisHost (), $ this ->getAuthRedisPort (), 'invalid ' );
49+ $ cache = new RedisCache ($ this ->getRedisHost (), $ this ->getRedisPort (), 'invalid ' );
6650 $ cache ->put ('foo ' , 'bar ' , 1 );
6751 }
6852
6953 /** @test */
7054 public function has ()
7155 {
72- if ($ this ->isSecure ()) {
73- $ this ->markTestSkipped ('This function needs an insecure instance ' );
74- }
75-
76- $ cache = new RedisCache ($ this ->getRedisHost (), $ this ->getAuthRedisPort ());
56+ $ cache = new RedisCache ($ this ->getRedisHost (), $ this ->getRedisPort (), 'secret ' );
7757 $ cache ->put ('foo ' , 'bar ' , 1 );
7858 static ::assertTrue ($ cache ->has ('foo ' ));
7959 }
8060
8161 /** @test */
8262 public function has_not ()
8363 {
84- if ($ this ->isSecure ()) {
85- $ this ->markTestSkipped ('This function needs an insecure instance ' );
86- }
87-
88- $ cache = new RedisCache ($ this ->getRedisHost (), $ this ->getAuthRedisPort ());
64+ $ cache = new RedisCache ($ this ->getRedisHost (), $ this ->getRedisPort (), 'secret ' );
8965 static ::assertFalse ($ cache ->has ('foo ' ));
9066 }
9167
9268 /** @test */
9369 public function get_existing_key ()
9470 {
95- if ($ this ->isSecure ()) {
96- $ this ->markTestSkipped ('This function needs an insecure instance ' );
97- }
98-
99- $ cache = new RedisCache ($ this ->getRedisHost (), $ this ->getAuthRedisPort ());
71+ $ cache = new RedisCache ($ this ->getRedisHost (), $ this ->getRedisPort (), 'secret ' );
10072 $ cache ->put ('foo ' , 'bar ' , 5 );
10173 static ::assertTrue ($ cache ->has ('foo ' ));
10274 static ::assertEquals ('bar ' , $ cache ->get ('foo ' ));
@@ -105,22 +77,15 @@ public function get_existing_key()
10577 /** @test */
10678 public function get_non_existing_key ()
10779 {
108- if ($ this ->isSecure ()) {
109- $ this ->markTestSkipped ('This function needs an insecure instance ' );
110- }
111-
112- $ cache = new RedisCache ($ this ->getRedisHost (), $ this ->getAuthRedisPort ());
80+ $ cache = new RedisCache ($ this ->getRedisHost (), $ this ->getRedisPort (), 'secret ' );
11381 static ::assertNull ($ cache ->get ('foo ' ));
11482 }
11583
11684 /** @test */
11785 public function pull_existing_key ()
11886 {
119- if ($ this ->isSecure ()) {
120- $ this ->markTestSkipped ('This function needs an insecure instance ' );
121- }
12287
123- $ cache = new RedisCache ($ this ->getRedisHost (), $ this ->getAuthRedisPort () );
88+ $ cache = new RedisCache ($ this ->getRedisHost (), $ this ->getRedisPort (), ' secret ' );
12489 $ cache ->put ('foo ' , 'bar ' , 5 );
12590 static ::assertTrue ($ cache ->has ('foo ' ));
12691 static ::assertEquals ('bar ' , $ cache ->pull ('foo ' ));
@@ -131,11 +96,7 @@ public function pull_existing_key()
13196 /** @test */
13297 public function pull_non_existing_key ()
13398 {
134- if ($ this ->isSecure ()) {
135- $ this ->markTestSkipped ('This function needs an insecure instance ' );
136- }
137-
138- $ cache = new RedisCache ($ this ->getRedisHost (), $ this ->getAuthRedisPort ());
99+ $ cache = new RedisCache ($ this ->getRedisHost (), $ this ->getRedisPort (), 'secret ' );
139100 static ::assertNull ($ cache ->pull ('foo ' ));
140101 }
141102
@@ -161,18 +122,8 @@ protected function getRedisHost()
161122 *
162123 * @return int
163124 */
164- protected function getAuthRedisPort ()
125+ protected function getRedisPort ()
165126 {
166127 return (int ) ($ _ENV ['REDIS_PORT ' ] ?? 6380 );
167128 }
168-
169- /**
170- * is secure.
171- *
172- * @return int
173- */
174- protected function isSecure ()
175- {
176- return (bool ) ($ _ENV ['REDIS_SECURE ' ] ?? false );
177- }
178129}
0 commit comments