|
1 | 1 | <?php declare(strict_types=1);
|
2 | 2 |
|
3 |
| -namespace Illuminate\Testing; |
4 |
| - |
5 |
| -use Mockery\MockInterface; |
6 |
| -use Nuwave\Lighthouse\Subscriptions\Contracts\Broadcaster; |
7 |
| -use PHPUnit\Framework\TestCase; |
8 |
| - |
9 |
| -class TestResponse |
10 |
| -{ |
11 |
| - /** |
12 |
| - * Assert the response contains an error with a matching message. |
13 |
| - * |
14 |
| - * @param \Throwable $error the expected error |
15 |
| - * |
16 |
| - * @return $this |
17 |
| - */ |
18 |
| - public function assertGraphQLError(\Throwable $error): self |
19 |
| - { |
20 |
| - return $this; |
21 |
| - } |
22 |
| - |
23 |
| - /** |
24 |
| - * Assert the response contains an error with the given message. |
25 |
| - * |
26 |
| - * @param string $message the expected error message |
27 |
| - * |
28 |
| - * @return $this |
29 |
| - */ |
30 |
| - public function assertGraphQLErrorMessage(string $message): self |
31 |
| - { |
32 |
| - return $this; |
33 |
| - } |
34 |
| - |
35 |
| - /** |
36 |
| - * Assert the response contains an error with the given debug message. |
37 |
| - * |
38 |
| - * Requires the config `lighthouse.debug` to include the option \GraphQL\Error\DebugFlag::INCLUDE_DEBUG_MESSAGE. |
39 |
| - * |
40 |
| - * @param string $message the expected debug message |
41 |
| - * |
42 |
| - * @return $this |
43 |
| - */ |
44 |
| - public function assertGraphQLDebugMessage(string $message): self |
45 |
| - { |
46 |
| - return $this; |
47 |
| - } |
48 |
| - |
49 |
| - /** |
50 |
| - * Assert the response contains no errors. |
51 |
| - * |
52 |
| - * @return $this |
53 |
| - */ |
54 |
| - public function assertGraphQLErrorFree(): self |
55 |
| - { |
56 |
| - return $this; |
57 |
| - } |
58 |
| - |
59 |
| - /** |
60 |
| - * Assert the returned result contains exactly the given validation keys. |
61 |
| - * |
62 |
| - * @param array<string> $keys the validation keys the result should have |
63 |
| - * |
64 |
| - * @return $this |
65 |
| - */ |
66 |
| - public function assertGraphQLValidationKeys(array $keys): self |
67 |
| - { |
68 |
| - return $this; |
69 |
| - } |
70 |
| - |
71 |
| - /** |
72 |
| - * Assert a given validation error is present in the response. |
73 |
| - * |
74 |
| - * @param string $key the validation key that should be present |
75 |
| - * @param string $message the expected validation message |
76 |
| - * |
77 |
| - * @return $this |
78 |
| - */ |
79 |
| - public function assertGraphQLValidationError(string $key, string $message): self |
80 |
| - { |
81 |
| - return $this; |
82 |
| - } |
83 |
| - |
84 |
| - /** |
85 |
| - * Assert no validation errors are present in the response. |
86 |
| - * |
87 |
| - * @return $this |
88 |
| - */ |
89 |
| - public function assertGraphQLValidationPasses(): self |
90 |
| - { |
91 |
| - return $this; |
92 |
| - } |
93 |
| - |
94 |
| - /** |
95 |
| - * Assert current user is authorized to join a subscription. |
96 |
| - * |
97 |
| - * @param TestCase $testClassInstance usually $this when calling this from a test class |
98 |
| - * |
99 |
| - * @return $this |
100 |
| - */ |
101 |
| - public function assertGraphQLSubscriptionAuthorized(TestCase $testClassInstance): self |
102 |
| - { |
103 |
| - return $this; |
104 |
| - } |
105 |
| - |
106 |
| - /** |
107 |
| - * Assert current user is NOT authorized to join a subscription. |
108 |
| - * |
109 |
| - * @param TestCase $testClassInstance usually $this when calling this from a test class |
110 |
| - * |
111 |
| - * @return $this |
112 |
| - */ |
113 |
| - public function assertGraphQLSubscriptionNotAuthorized(TestCase $testClassInstance): self |
114 |
| - { |
115 |
| - return $this; |
116 |
| - } |
117 |
| - |
118 |
| - /** |
119 |
| - * For cases where you need more control over your broadcast assertions. |
120 |
| - * |
121 |
| - * @see \Nuwave\Lighthouse\Testing\TestResponseMixin::assertGraphQLBroadcasted |
122 |
| - * @see \Nuwave\Lighthouse\Testing\TestResponseMixin::assertGraphQLNotBroadcasted |
123 |
| - * |
124 |
| - * @return \Mockery\MockInterface&\Nuwave\Lighthouse\Subscriptions\Contracts\Broadcaster |
125 |
| - */ |
126 |
| - public function graphQLSubscriptionMock() // @phpstan-ignore-line invalid return type? |
127 |
| - { |
128 |
| - $mock = \Mockery::mock(Broadcaster::class); |
129 |
| - assert($mock instanceof Broadcaster && $mock instanceof MockInterface); |
130 |
| - |
131 |
| - return $mock; |
132 |
| - } |
133 |
| - |
134 |
| - /** Get the channel name from a subscription query. */ |
135 |
| - public function graphQLSubscriptionChannelName(): string |
136 |
| - { |
137 |
| - return ''; |
138 |
| - } |
| 3 | +namespace Nuwave\Lighthouse\Subscriptions\Contracts { |
| 4 | + interface Broadcaster {} |
| 5 | +} |
139 | 6 |
|
140 |
| - /** |
141 |
| - * Assert the subscription received the given broadcasts. |
142 |
| - * |
143 |
| - * @param array<int, array<string, mixed>> $data the broadcast pattern that you are expecting |
144 |
| - * |
145 |
| - * @return $this |
146 |
| - */ |
147 |
| - public function assertGraphQLBroadcasted(array $data): self |
148 |
| - { |
149 |
| - return $this; |
150 |
| - } |
| 7 | +namespace Illuminate\Testing { |
| 8 | + use Mockery\MockInterface; |
| 9 | + use Nuwave\Lighthouse\Subscriptions\Contracts\Broadcaster; |
| 10 | + use PHPUnit\Framework\TestCase; |
151 | 11 |
|
152 |
| - /** |
153 |
| - * Assert the subscription received no broadcast. |
154 |
| - * |
155 |
| - * @return $this |
156 |
| - */ |
157 |
| - public function assertGraphQLNotBroadcasted(): self |
| 12 | + class TestResponse |
158 | 13 | {
|
159 |
| - return $this; |
| 14 | + /** |
| 15 | + * Assert the response contains an error with a matching message. |
| 16 | + * |
| 17 | + * @param \Throwable $error the expected error |
| 18 | + * |
| 19 | + * @return $this |
| 20 | + */ |
| 21 | + public function assertGraphQLError(\Throwable $error): self |
| 22 | + { |
| 23 | + return $this; |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * Assert the response contains an error with the given message. |
| 28 | + * |
| 29 | + * @param string $message the expected error message |
| 30 | + * |
| 31 | + * @return $this |
| 32 | + */ |
| 33 | + public function assertGraphQLErrorMessage(string $message): self |
| 34 | + { |
| 35 | + return $this; |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Assert the response contains an error with the given debug message. |
| 40 | + * |
| 41 | + * Requires the config `lighthouse.debug` to include the option \GraphQL\Error\DebugFlag::INCLUDE_DEBUG_MESSAGE. |
| 42 | + * |
| 43 | + * @param string $message the expected debug message |
| 44 | + * |
| 45 | + * @return $this |
| 46 | + */ |
| 47 | + public function assertGraphQLDebugMessage(string $message): self |
| 48 | + { |
| 49 | + return $this; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Assert the response contains no errors. |
| 54 | + * |
| 55 | + * @return $this |
| 56 | + */ |
| 57 | + public function assertGraphQLErrorFree(): self |
| 58 | + { |
| 59 | + return $this; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Assert the returned result contains exactly the given validation keys. |
| 64 | + * |
| 65 | + * @param array<string> $keys the validation keys the result should have |
| 66 | + * |
| 67 | + * @return $this |
| 68 | + */ |
| 69 | + public function assertGraphQLValidationKeys(array $keys): self |
| 70 | + { |
| 71 | + return $this; |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Assert a given validation error is present in the response. |
| 76 | + * |
| 77 | + * @param string $key the validation key that should be present |
| 78 | + * @param string $message the expected validation message |
| 79 | + * |
| 80 | + * @return $this |
| 81 | + */ |
| 82 | + public function assertGraphQLValidationError(string $key, string $message): self |
| 83 | + { |
| 84 | + return $this; |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Assert no validation errors are present in the response. |
| 89 | + * |
| 90 | + * @return $this |
| 91 | + */ |
| 92 | + public function assertGraphQLValidationPasses(): self |
| 93 | + { |
| 94 | + return $this; |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Assert current user is authorized to join a subscription. |
| 99 | + * |
| 100 | + * @param \PHPUnit\Framework\TestCase $testClassInstance usually $this when calling this from a test class |
| 101 | + * |
| 102 | + * @return $this |
| 103 | + */ |
| 104 | + public function assertGraphQLSubscriptionAuthorized(TestCase $testClassInstance): self |
| 105 | + { |
| 106 | + return $this; |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Assert current user is NOT authorized to join a subscription. |
| 111 | + * |
| 112 | + * @param \PHPUnit\Framework\TestCase $testClassInstance usually $this when calling this from a test class |
| 113 | + * |
| 114 | + * @return $this |
| 115 | + */ |
| 116 | + public function assertGraphQLSubscriptionNotAuthorized(TestCase $testClassInstance): self |
| 117 | + { |
| 118 | + return $this; |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * For cases where you need more control over your broadcast assertions. |
| 123 | + * |
| 124 | + * @return \Nuwave\Lighthouse\Subscriptions\Contracts\Broadcaster&\Mockery\MockInterface |
| 125 | + * |
| 126 | + * @see \Nuwave\Lighthouse\Testing\TestResponseMixin::assertGraphQLNotBroadcasted |
| 127 | + * @see \Nuwave\Lighthouse\Testing\TestResponseMixin::assertGraphQLBroadcasted |
| 128 | + */ |
| 129 | + public function graphQLSubscriptionMock(): Broadcaster |
| 130 | + { |
| 131 | + $mock = \Mockery::mock(Broadcaster::class); |
| 132 | + assert($mock instanceof Broadcaster && $mock instanceof MockInterface); |
| 133 | + |
| 134 | + return $mock; |
| 135 | + } |
| 136 | + |
| 137 | + /** Get the channel name from a subscription query. */ |
| 138 | + public function graphQLSubscriptionChannelName(): string |
| 139 | + { |
| 140 | + return ''; |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * Assert the subscription received the given broadcasts. |
| 145 | + * |
| 146 | + * @param array<int, array<string, mixed>> $data the broadcast pattern that you are expecting |
| 147 | + * |
| 148 | + * @return $this |
| 149 | + */ |
| 150 | + public function assertGraphQLBroadcasted(array $data): self |
| 151 | + { |
| 152 | + return $this; |
| 153 | + } |
| 154 | + |
| 155 | + /** |
| 156 | + * Assert the subscription received no broadcast. |
| 157 | + * |
| 158 | + * @return $this |
| 159 | + */ |
| 160 | + public function assertGraphQLNotBroadcasted(): self |
| 161 | + { |
| 162 | + return $this; |
| 163 | + } |
160 | 164 | }
|
161 | 165 | }
|
0 commit comments