-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRedisExtension.php
44 lines (32 loc) · 1.11 KB
/
RedisExtension.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace Enqueue\Test;
use Enqueue\Redis\PhpRedis;
use Enqueue\Redis\PRedis;
use Enqueue\Redis\RedisConnectionFactory;
use Enqueue\Redis\RedisContext;
use PHPUnit\Framework\SkippedTestError;
trait RedisExtension
{
private function buildPhpRedisContext(): RedisContext
{
if (false == getenv('PHPREDIS_DSN')) {
throw new SkippedTestError('Functional tests are not allowed in this environment');
}
$config = getenv('PHPREDIS_DSN');
$context = (new RedisConnectionFactory($config))->createContext();
// guard
$this->assertInstanceOf(PhpRedis::class, $context->getRedis());
return $context;
}
private function buildPRedisContext(): RedisContext
{
if (false == getenv('PREDIS_DSN')) {
throw new SkippedTestError('Functional tests are not allowed in this environment');
}
$config = getenv('PREDIS_DSN');
$context = (new RedisConnectionFactory($config))->createContext();
// guard
$this->assertInstanceOf(PRedis::class, $context->getRedis());
return $context;
}
}