@@ -116,9 +116,10 @@ public function testExecuteWebhookThrowsPayPalApiException(): void
116
116
$ context ->addExtension (self ::THROW_PAYPAL_API_EXCEPTION , new ArrayStruct ());
117
117
$ request = $ this ->createRequestWithWebhookData ();
118
118
119
- $ this ->expectException (BadRequestHttpException::class);
120
- $ this ->expectExceptionMessage ('An error occurred during execution of webhook ' );
121
- $ this ->controller ->executeWebhook ($ request , $ context );
119
+ $ response = $ this ->controller ->executeWebhook ($ request , $ context );
120
+
121
+ static ::assertSame ('An error occurred during execution of webhook ' , $ response ->getContent ());
122
+ static ::assertSame (Response::HTTP_BAD_REQUEST , $ response ->getStatusCode ());
122
123
123
124
static ::assertTrue (
124
125
$ this ->logger ->hasRecordThatContains ('testPayPalApiExceptionMessage ' , Level::Error),
@@ -132,9 +133,10 @@ public function testExecuteWebhookThrowsWebhookException(): void
132
133
$ context ->addExtension (self ::THROW_WEBHOOK_EXCEPTION , new ArrayStruct ());
133
134
$ request = $ this ->createRequestWithWebhookData ();
134
135
135
- $ this ->expectException (BadRequestHttpException::class);
136
- $ this ->expectExceptionMessage ('An error occurred during execution of webhook ' );
137
- $ this ->controller ->executeWebhook ($ request , $ context );
136
+ $ response = $ this ->controller ->executeWebhook ($ request , $ context );
137
+
138
+ static ::assertSame ('An error occurred during execution of webhook ' , $ response ->getContent ());
139
+ static ::assertSame (Response::HTTP_BAD_REQUEST , $ response ->getStatusCode ());
138
140
139
141
static ::assertTrue (
140
142
$ this ->logger ->hasRecordThatContains ('testWebhookExceptionMessage ' , Level::Error),
@@ -148,9 +150,10 @@ public function testExecuteWebhookThrowsGeneralException(): void
148
150
$ context ->addExtension (self ::THROW_GENERAL_EXCEPTION , new ArrayStruct ());
149
151
$ request = $ this ->createRequestWithWebhookData ();
150
152
151
- $ this ->expectException (BadRequestHttpException::class);
152
- $ this ->expectExceptionMessage ('An error occurred during execution of webhook ' );
153
- $ this ->controller ->executeWebhook ($ request , $ context );
153
+ $ response = $ this ->controller ->executeWebhook ($ request , $ context );
154
+
155
+ static ::assertSame ('An error occurred during execution of webhook ' , $ response ->getContent ());
156
+ static ::assertSame (Response::HTTP_BAD_REQUEST , $ response ->getStatusCode ());
154
157
155
158
static ::assertTrue (
156
159
$ this ->logger ->hasRecordThatContains ('testGeneralExceptionMessage ' , Level::Error),
@@ -164,19 +167,26 @@ public function testExecuteWebhookEmptyToken(): void
164
167
$ context ->addExtension (self ::EMPTY_TOKEN , new ArrayStruct ());
165
168
$ request = $ this ->createRequestWithWebhookData ();
166
169
167
- $ this ->expectException (BadRequestHttpException::class);
168
- $ this ->expectExceptionMessage ('Shopware token is invalid ' );
169
- $ this ->controller ->executeWebhook ($ request , $ context );
170
+ $ response = $ this ->controller ->executeWebhook ($ request , $ context );
171
+
172
+ static ::assertSame ('Shopware token is invalid ' , $ response ->getContent ());
173
+ static ::assertSame (Response::HTTP_BAD_REQUEST , $ response ->getStatusCode ());
174
+ static ::assertTrue (
175
+ $ this ->logger ->hasRecordThatContains ('Shopware token of webhook "{webhookId}" is invalid ' , Level::Warning),
176
+ 'Expected invalid-shopware-token log entry not found ' ,
177
+ );
170
178
}
171
179
172
180
public function testExecuteWebhookEmptyTokenSent (): void
173
181
{
174
182
$ context = Context::createDefaultContext ();
175
183
$ request = new Request ();
176
184
177
- $ this ->expectException (BadRequestHttpException::class);
178
- $ this ->expectExceptionMessage ('Shopware token is invalid ' );
179
- $ this ->controller ->executeWebhook ($ request , $ context );
185
+ $ response = $ this ->controller ->executeWebhook ($ request , $ context );
186
+
187
+ static ::assertSame ('Shopware token is invalid ' , $ response ->getContent ());
188
+ static ::assertSame (Response::HTTP_BAD_REQUEST , $ response ->getStatusCode ());
189
+ static ::assertEquals ([], $ this ->logger ->getRecords ());
180
190
}
181
191
182
192
public function testExecuteWebhookInvalidToken (): void
@@ -186,9 +196,27 @@ public function testExecuteWebhookInvalidToken(): void
186
196
[WebhookService::PAYPAL_WEBHOOK_TOKEN_NAME => 'invalid-token ' ]
187
197
);
188
198
189
- $ this ->expectException (BadRequestHttpException::class);
190
- $ this ->expectExceptionMessage ('Shopware token is invalid ' );
191
- $ this ->controller ->executeWebhook ($ request , $ context );
199
+ $ response = $ this ->controller ->executeWebhook ($ request , $ context );
200
+
201
+ static ::assertSame ('Shopware token is invalid ' , $ response ->getContent ());
202
+ static ::assertSame (Response::HTTP_BAD_REQUEST , $ response ->getStatusCode ());
203
+ static ::assertEquals ([], $ this ->logger ->getRecords ());
204
+ }
205
+
206
+ public function testExecuteWebhookInvalidTokenWithId (): void
207
+ {
208
+ $ context = Context::createDefaultContext ();
209
+ $ request = $ this ->createRequestWithWebhookData ();
210
+ $ request ->query ->set (WebhookService::PAYPAL_WEBHOOK_TOKEN_NAME , 'invalid-token ' );
211
+
212
+ $ response = $ this ->controller ->executeWebhook ($ request , $ context );
213
+
214
+ static ::assertSame ('Shopware token is invalid ' , $ response ->getContent ());
215
+ static ::assertSame (Response::HTTP_BAD_REQUEST , $ response ->getStatusCode ());
216
+ static ::assertTrue (
217
+ $ this ->logger ->hasRecordThatContains ('Shopware token of webhook "{webhookId}" is invalid ' , Level::Warning),
218
+ 'Expected invalid-shopware-token log entry not found ' ,
219
+ );
192
220
}
193
221
194
222
public function testExecuteWebhookNoData (): void
0 commit comments