-
-
Notifications
You must be signed in to change notification settings - Fork 466
Expand file tree
/
Copy pathSubscriberTest.php
More file actions
95 lines (66 loc) · 2.92 KB
/
SubscriberTest.php
File metadata and controls
95 lines (66 loc) · 2.92 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php declare(strict_types=1);
namespace Tests\Unit\Subscriptions;
use GraphQL\Language\AST\OperationDefinitionNode;
use Illuminate\Config\Repository as ConfigRepository;
use Illuminate\Http\Request;
use Nuwave\Lighthouse\Execution\HttpGraphQLContext;
use Nuwave\Lighthouse\Execution\ResolveInfo;
use Nuwave\Lighthouse\Subscriptions\Subscriber;
use Tests\EnablesSubscriptionServiceProvider;
use Tests\TestCase;
use Tests\TestsSerialization;
final class SubscriberTest extends TestCase
{
use TestsSerialization;
use EnablesSubscriptionServiceProvider;
protected function getEnvironmentSetUp($app): void
{
parent::getEnvironmentSetUp($app);
$this->useSerializingArrayStore();
$this->fakeContextSerializer();
}
public function testSerializable(): void
{
$args = ['foo' => 'bar'];
$resolveInfo = $this->createStub(ResolveInfo::class);
$fieldName = 'baz';
$resolveInfo->fieldName = $fieldName;
$resolveInfo->operation = new OperationDefinitionNode([]);
$resolveInfo->fragments = [];
$context = new HttpGraphQLContext(new Request());
$subscriber = new Subscriber($args, $context, $resolveInfo);
$topic = 'topic';
$subscriber->topic = $topic;
$channel = $subscriber->channel;
// @phpstan-ignore theCodingMachineSafe.function (Safe\unserialize is not available in thecodingmachine/safe ^1 and ^2)
$serialized = unserialize(serialize($subscriber));
$this->assertInstanceOf(Subscriber::class, $serialized);
$this->assertSame($args, $serialized->args);
$this->assertSame($channel, $serialized->channel);
$this->assertSame($topic, $serialized->topic);
$this->assertSame($fieldName, $serialized->fieldName);
}
public function testEncryptedChannels(): void
{
$args = ['foo' => 'bar'];
$resolveInfo = $this->createStub(ResolveInfo::class);
$fieldName = 'baz';
$resolveInfo->fieldName = $fieldName;
$resolveInfo->operation = new OperationDefinitionNode([]);
$resolveInfo->fragments = [];
$context = new HttpGraphQLContext(new Request());
$config = $this->app->make(ConfigRepository::class);
$config->set('lighthouse.subscriptions.encrypted_channels', true);
$encryptedSubscriber = new Subscriber($args, $context, $resolveInfo);
$topic = 'topic';
$encryptedSubscriber->topic = $topic;
$channel = $encryptedSubscriber->channel;
$this->assertStringStartsWith('private-encrypted-lighthouse-', $channel);
$config->set('lighthouse.subscriptions.encrypted_channels', false);
$encryptedSubscriber = new Subscriber($args, $context, $resolveInfo);
$topic = 'topic';
$encryptedSubscriber->topic = $topic;
$channel = $encryptedSubscriber->channel;
$this->assertStringStartsWith('private-lighthouse-', $channel);
}
}