|
2 | 2 |
|
3 | 3 | namespace Enqueue\Test; |
4 | 4 |
|
| 5 | +use Enqueue\Redis\PhpRedis; |
| 6 | +use Enqueue\Redis\PRedis; |
5 | 7 | use Enqueue\Redis\RedisConnectionFactory; |
6 | 8 | use Enqueue\Redis\RedisContext; |
7 | 9 |
|
8 | 10 | trait RedisExtension |
9 | 11 | { |
10 | | - /** |
11 | | - * @return RedisContext |
12 | | - */ |
13 | | - private function buildPhpRedisContext() |
| 12 | + private function buildPhpRedisContext(): RedisContext |
14 | 13 | { |
15 | | - if (false == getenv('REDIS_HOST')) { |
| 14 | + if (false == getenv('PHPREDIS_DSN')) { |
16 | 15 | throw new \PHPUnit_Framework_SkippedTestError('Functional tests are not allowed in this environment'); |
17 | 16 | } |
18 | 17 |
|
19 | | - $config = [ |
20 | | - 'host' => getenv('REDIS_HOST'), |
21 | | - 'port' => (int) getenv('REDIS_PORT'), |
22 | | - 'vendor' => 'phpredis', |
23 | | - 'lazy' => false, |
24 | | - ]; |
| 18 | + $config = getenv('PHPREDIS_DSN'); |
25 | 19 |
|
26 | | - return (new RedisConnectionFactory($config))->createContext(); |
| 20 | + $context = (new RedisConnectionFactory($config))->createContext(); |
| 21 | + |
| 22 | + //guard |
| 23 | + $this->assertInstanceOf(PhpRedis::class, $context->getRedis()); |
| 24 | + |
| 25 | + return $context; |
27 | 26 | } |
28 | 27 |
|
29 | | - /** |
30 | | - * @return RedisContext |
31 | | - */ |
32 | | - private function buildPRedisContext() |
| 28 | + private function buildPRedisContext(): RedisContext |
33 | 29 | { |
34 | | - if (false == getenv('REDIS_HOST')) { |
| 30 | + if (false == getenv('PREDIS_DSN')) { |
35 | 31 | throw new \PHPUnit_Framework_SkippedTestError('Functional tests are not allowed in this environment'); |
36 | 32 | } |
37 | 33 |
|
38 | | - $config = [ |
39 | | - 'host' => getenv('REDIS_HOST'), |
40 | | - 'port' => getenv('REDIS_PORT'), |
41 | | - 'vendor' => 'predis', |
42 | | - 'lazy' => false, |
43 | | - ]; |
| 34 | + $config = getenv('PREDIS_DSN'); |
| 35 | + |
| 36 | + $context = (new RedisConnectionFactory($config))->createContext(); |
| 37 | + |
| 38 | + //guard |
| 39 | + $this->assertInstanceOf(PRedis::class, $context->getRedis()); |
44 | 40 |
|
45 | | - return (new RedisConnectionFactory($config))->createContext(); |
| 41 | + return $context; |
46 | 42 | } |
47 | 43 | } |
0 commit comments