@@ -143,6 +143,49 @@ public function testExecuteProcessesValidWebhook($payload, $eventType): void
143143 $ this ->assertInstanceOf (ResultInterface::class, $ this ->controller ->execute ());
144144 }
145145
146+ /**
147+ * @dataProvider dataProviderProcessValidWebhook
148+ *
149+ * @param $payload
150+ * @param $eventType
151+ * @return void
152+ * @throws Exception
153+ * @throws NotFoundException
154+ */
155+ public function testExecuteProcessesDuplicateWebhook ($ payload , $ eventType ): void
156+ {
157+ $ _SERVER ['PHP_AUTH_USER ' ] = 'user ' ;
158+ $ _SERVER ['PHP_AUTH_PW ' ] = 'pass ' ;
159+
160+ $ this ->configHelperMock ->method ('getNotificationsUsername ' )->willReturn ('user ' );
161+ $ this ->configHelperMock ->method ('getNotificationsPassword ' )->willReturn ('pass ' );
162+
163+ $ notification = $ this ->createMock (Notification::class);
164+ $ notification ->method ('getPspreference ' )->willReturn ('ABC12345678XYZ ' );
165+ $ notification ->method ('isDuplicate ' )->willReturn (true );
166+
167+ $ this ->adyenNotificationRepositoryMock ->expects ($ this ->never ())->method ('save ' );
168+
169+ $ acceptorMock = $ this ->createMock (WebhookAcceptorInterface::class);
170+ $ acceptorMock ->method ('getNotifications ' )->willReturn ([$ notification ]);
171+
172+ $ this ->requestMock ->method ('getContent ' )->willReturn (json_encode ($ payload ));
173+ $ this ->webhookAcceptorFactoryMock ->method ('getAcceptor ' )
174+ ->with ($ eventType )
175+ ->willReturn ($ acceptorMock );
176+
177+ $ this ->adyenLoggerMock ->expects ($ this ->once ())
178+ ->method ('addAdyenResult ' )
179+ ->with ('Duplicate notification with pspReference ABC12345678XYZ has been skipped. ' );
180+
181+ $ this ->webhookHelperMock ->method ('isIpValid ' )->willReturn (true );
182+
183+ $ this ->resultMock ->expects ($ this ->once ())->method ('setStatusHeader ' )->with (200 );
184+ $ this ->resultMock ->expects ($ this ->once ())->method ('setContents ' )->with ('[accepted] ' );
185+
186+ $ this ->assertInstanceOf (ResultInterface::class, $ this ->controller ->execute ());
187+ }
188+
146189 public function testWebhookUnidentifiedEventType (): void
147190 {
148191 $ _SERVER ['PHP_AUTH_USER ' ] = 'user ' ;
@@ -238,26 +281,4 @@ public function testExecuteOnGenericError(): void
238281 ->with ('An error occurred while handling this webhook! ' );
239282 $ this ->assertInstanceOf (ResultInterface::class, $ this ->controller ->execute ());
240283 }
241-
242- public function testExecuteOnDuplicateWebhook (): void
243- {
244- $ _SERVER ['PHP_AUTH_USER ' ] = 'user ' ;
245- $ _SERVER ['PHP_AUTH_PW ' ] = 'pass ' ;
246-
247- $ this ->configHelperMock ->method ('getNotificationsUsername ' )->willReturn ('user ' );
248- $ this ->configHelperMock ->method ('getNotificationsPassword ' )->willReturn ('pass ' );
249- $ this ->webhookHelperMock ->method ('isIpValid ' )->willReturn (true );
250-
251- $ payload = ['type ' => 'token.created ' ];
252- $ this ->requestMock ->method ('getContent ' )->willReturn (json_encode ($ payload ));
253-
254- $ acceptorMock = $ this ->createMock (TokenWebhookAcceptor::class);
255- $ acceptorMock ->method ('getNotifications ' )->willThrowException (new AlreadyExistsException ());
256- $ this ->webhookAcceptorFactoryMock ->method ('getAcceptor ' )->willReturn ($ acceptorMock );
257-
258- $ this ->resultMock ->expects ($ this ->once ())->method ('setStatusHeader ' )->with (400 );
259- $ this ->resultMock ->expects ($ this ->once ())->method ('setContents ' )
260- ->with ('Webhook already exists! ' );
261- $ this ->assertInstanceOf (ResultInterface::class, $ this ->controller ->execute ());
262- }
263284}
0 commit comments