-
-
Notifications
You must be signed in to change notification settings - Fork 438
/
TestsRedis.php
54 lines (46 loc) · 1.55 KB
/
TestsRedis.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
45
46
47
48
49
50
51
52
53
54
<?php declare(strict_types=1);
namespace Tests;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Illuminate\Support\Facades\Redis;
use Nuwave\Lighthouse\Subscriptions\SubscriptionRouter;
trait TestsRedis
{
protected function tearDown(): void
{
Redis::flushdb();
parent::tearDown();
}
protected function getEnvironmentSetUp($app): void
{
parent::getEnvironmentSetUp($app);
$config = $app->make(ConfigRepository::class);
$config->set('database.redis.default', [
'url' => env('LIGHTHOUSE_TEST_REDIS_URL'),
'host' => env('LIGHTHOUSE_TEST_REDIS_HOST', 'redis'),
'password' => env('LIGHTHOUSE_TEST_REDIS_PASSWORD'),
'port' => env('LIGHTHOUSE_TEST_REDIS_PORT', '6379'),
'database' => env('LIGHTHOUSE_TEST_REDIS_DB', '0'),
]);
$config->set('database.redis.options', [
'prefix' => 'lighthouse-test-',
]);
$config->set('lighthouse.subscriptions', [
'storage' => 'redis',
'broadcaster' => 'echo',
'broadcasters' => [
'echo' => [
'driver' => 'echo',
'routes' => SubscriptionRouter::class . '@echoRoutes',
],
],
]);
}
protected function assertRedisHas(string $key): void
{
$this->assertGreaterThanOrEqual(1, Redis::exists($key));
}
protected function assertRedisMissing(string $key): void
{
$this->assertSame(0, Redis::exists($key));
}
}