1010use Ibexa \Contracts \Core \Repository \Events \Notification \BeforeCreateNotificationEvent ;
1111use Ibexa \Contracts \Core \Repository \Events \Notification \BeforeDeleteNotificationEvent ;
1212use Ibexa \Contracts \Core \Repository \Events \Notification \BeforeMarkNotificationAsReadEvent ;
13+ use Ibexa \Contracts \Core \Repository \Events \Notification \BeforeMarkNotificationAsUnreadEvent ;
1314use Ibexa \Contracts \Core \Repository \Events \Notification \CreateNotificationEvent ;
1415use Ibexa \Contracts \Core \Repository \Events \Notification \DeleteNotificationEvent ;
1516use Ibexa \Contracts \Core \Repository \Events \Notification \MarkNotificationAsReadEvent ;
17+ use Ibexa \Contracts \Core \Repository \Events \Notification \MarkNotificationAsUnreadEvent ;
1618use Ibexa \Contracts \Core \Repository \NotificationService as NotificationServiceInterface ;
1719use Ibexa \Contracts \Core \Repository \Values \Notification \CreateStruct ;
1820use Ibexa \Contracts \Core \Repository \Values \Notification \Notification ;
@@ -64,9 +66,13 @@ public function testReturnCreateNotificationResultInBeforeEvents()
6466 $ innerServiceMock = $ this ->createMock (NotificationServiceInterface::class);
6567 $ innerServiceMock ->method ('createNotification ' )->willReturn ($ notification );
6668
67- $ traceableEventDispatcher ->addListener (BeforeCreateNotificationEvent::class, static function (BeforeCreateNotificationEvent $ event ) use ($ eventNotification ) {
68- $ event ->setNotification ($ eventNotification );
69- }, 10 );
69+ $ traceableEventDispatcher ->addListener (
70+ BeforeCreateNotificationEvent::class,
71+ static function (BeforeCreateNotificationEvent $ event ) use ($ eventNotification ): void {
72+ $ event ->setNotification ($ eventNotification );
73+ },
74+ 10
75+ );
7076
7177 $ service = new NotificationService ($ innerServiceMock , $ traceableEventDispatcher );
7278 $ result = $ service ->createNotification (...$ parameters );
@@ -98,10 +104,14 @@ public function testCreateNotificationStopPropagationInBeforeEvents()
98104 $ innerServiceMock = $ this ->createMock (NotificationServiceInterface::class);
99105 $ innerServiceMock ->method ('createNotification ' )->willReturn ($ notification );
100106
101- $ traceableEventDispatcher ->addListener (BeforeCreateNotificationEvent::class, static function (BeforeCreateNotificationEvent $ event ) use ($ eventNotification ) {
102- $ event ->setNotification ($ eventNotification );
103- $ event ->stopPropagation ();
104- }, 10 );
107+ $ traceableEventDispatcher ->addListener (
108+ BeforeCreateNotificationEvent::class,
109+ static function (BeforeCreateNotificationEvent $ event ) use ($ eventNotification ): void {
110+ $ event ->setNotification ($ eventNotification );
111+ $ event ->stopPropagation ();
112+ },
113+ 10
114+ );
105115
106116 $ service = new NotificationService ($ innerServiceMock , $ traceableEventDispatcher );
107117 $ result = $ service ->createNotification (...$ parameters );
@@ -157,9 +167,13 @@ public function testDeleteNotificationStopPropagationInBeforeEvents()
157167
158168 $ innerServiceMock = $ this ->createMock (NotificationServiceInterface::class);
159169
160- $ traceableEventDispatcher ->addListener (BeforeDeleteNotificationEvent::class, static function (BeforeDeleteNotificationEvent $ event ) {
161- $ event ->stopPropagation ();
162- }, 10 );
170+ $ traceableEventDispatcher ->addListener (
171+ BeforeDeleteNotificationEvent::class,
172+ static function (BeforeDeleteNotificationEvent $ event ): void {
173+ $ event ->stopPropagation ();
174+ },
175+ 10
176+ );
163177
164178 $ service = new NotificationService ($ innerServiceMock , $ traceableEventDispatcher );
165179 $ service ->deleteNotification (...$ parameters );
@@ -201,6 +215,31 @@ public function testMarkNotificationAsReadEvents()
201215 self ::assertSame ([], $ traceableEventDispatcher ->getNotCalledListeners ());
202216 }
203217
218+ public function testMarkNotificationAsUnreadEvents (): void
219+ {
220+ $ traceableEventDispatcher = $ this ->getEventDispatcher (
221+ BeforeMarkNotificationAsUnreadEvent::class,
222+ MarkNotificationAsUnreadEvent::class
223+ );
224+
225+ $ parameters = [
226+ $ this ->createMock (Notification::class),
227+ ];
228+
229+ $ innerServiceMock = $ this ->createMock (NotificationServiceInterface::class);
230+
231+ $ service = new NotificationService ($ innerServiceMock , $ traceableEventDispatcher );
232+ $ service ->markNotificationAsUnread (...$ parameters );
233+
234+ $ calledListeners = $ this ->getListenersStack ($ traceableEventDispatcher ->getCalledListeners ());
235+
236+ self ::assertSame ($ calledListeners , [
237+ [BeforeMarkNotificationAsUnreadEvent::class, 0 ],
238+ [MarkNotificationAsUnreadEvent::class, 0 ],
239+ ]);
240+ self ::assertSame ([], $ traceableEventDispatcher ->getNotCalledListeners ());
241+ }
242+
204243 public function testMarkNotificationAsReadStopPropagationInBeforeEvents ()
205244 {
206245 $ traceableEventDispatcher = $ this ->getEventDispatcher (
@@ -214,9 +253,13 @@ public function testMarkNotificationAsReadStopPropagationInBeforeEvents()
214253
215254 $ innerServiceMock = $ this ->createMock (NotificationServiceInterface::class);
216255
217- $ traceableEventDispatcher ->addListener (BeforeMarkNotificationAsReadEvent::class, static function (BeforeMarkNotificationAsReadEvent $ event ) {
218- $ event ->stopPropagation ();
219- }, 10 );
256+ $ traceableEventDispatcher ->addListener (
257+ BeforeMarkNotificationAsReadEvent::class,
258+ static function (BeforeMarkNotificationAsReadEvent $ event ): void {
259+ $ event ->stopPropagation ();
260+ },
261+ 10
262+ );
220263
221264 $ service = new NotificationService ($ innerServiceMock , $ traceableEventDispatcher );
222265 $ service ->markNotificationAsRead (...$ parameters );
@@ -232,4 +275,40 @@ public function testMarkNotificationAsReadStopPropagationInBeforeEvents()
232275 [MarkNotificationAsReadEvent::class, 0 ],
233276 ]);
234277 }
278+
279+ public function testMarkNotificationAsUnreadStopPropagationInBeforeEvents (): void
280+ {
281+ $ traceableEventDispatcher = $ this ->getEventDispatcher (
282+ BeforeMarkNotificationAsUnreadEvent::class,
283+ MarkNotificationAsUnreadEvent::class
284+ );
285+
286+ $ parameters = [
287+ $ this ->createMock (Notification::class),
288+ ];
289+
290+ $ innerServiceMock = $ this ->createMock (NotificationServiceInterface::class);
291+
292+ $ traceableEventDispatcher ->addListener (
293+ BeforeMarkNotificationAsUnreadEvent::class,
294+ static function (BeforeMarkNotificationAsUnreadEvent $ event ): void {
295+ $ event ->stopPropagation ();
296+ },
297+ 10
298+ );
299+
300+ $ service = new NotificationService ($ innerServiceMock , $ traceableEventDispatcher );
301+ $ service ->markNotificationAsUnread (...$ parameters );
302+
303+ $ calledListeners = $ this ->getListenersStack ($ traceableEventDispatcher ->getCalledListeners ());
304+ $ notCalledListeners = $ this ->getListenersStack ($ traceableEventDispatcher ->getNotCalledListeners ());
305+
306+ self ::assertSame ($ calledListeners , [
307+ [BeforeMarkNotificationAsUnreadEvent::class, 10 ],
308+ ]);
309+ self ::assertSame ($ notCalledListeners , [
310+ [BeforeMarkNotificationAsUnreadEvent::class, 0 ],
311+ [MarkNotificationAsUnreadEvent::class, 0 ],
312+ ]);
313+ }
235314}
0 commit comments