88namespace OCA \Comments \Tests \Unit \Notification ;
99
1010use OCA \Comments \Notification \Listener ;
11- use OCP \Comments \CommentsEvent ;
11+ use OCP \Comments \Events \BeforeCommentUpdatedEvent ;
12+ use OCP \Comments \Events \CommentAddedEvent ;
13+ use OCP \Comments \Events \CommentDeletedEvent ;
14+ use OCP \Comments \Events \CommentUpdatedEvent ;
1215use OCP \Comments \IComment ;
1316use OCP \IURLGenerator ;
1417use OCP \IUserManager ;
@@ -37,10 +40,10 @@ protected function setUp(): void {
3740
3841 public static function eventProvider (): array {
3942 return [
40- [CommentsEvent:: EVENT_ADD , 'notify ' ],
41- [CommentsEvent:: EVENT_UPDATE , 'notify ' ],
42- [CommentsEvent:: EVENT_PRE_UPDATE , 'markProcessed ' ],
43- [CommentsEvent:: EVENT_DELETE , 'markProcessed ' ]
43+ [' add ' , 'notify ' ],
44+ [' update ' , 'notify ' ],
45+ [' pre_update ' , 'markProcessed ' ],
46+ [' delete ' , 'markProcessed ' ]
4447 ];
4548 }
4649
@@ -49,7 +52,7 @@ public static function eventProvider(): array {
4952 * @param string $notificationMethod
5053 */
5154 #[\PHPUnit \Framework \Attributes \DataProvider('eventProvider ' )]
52- public function testEvaluate ($ eventType , $ notificationMethod ): void {
55+ public function testEvaluate (string $ eventType , $ notificationMethod ): void {
5356 /** @var IComment|MockObject $comment */
5457 $ comment = $ this ->createMock (IComment::class);
5558 $ comment ->expects ($ this ->any ())
@@ -72,14 +75,12 @@ public function testEvaluate($eventType, $notificationMethod): void {
7275 ->method ('getId ' )
7376 ->willReturn ('1234 ' );
7477
75- /** @var CommentsEvent|MockObject $event */
76- $ event = $ this ->createMock (CommentsEvent::class);
77- $ event ->expects ($ this ->once ())
78- ->method ('getComment ' )
79- ->willReturn ($ comment );
80- $ event ->expects (($ this ->any ()))
81- ->method (('getEvent ' ))
82- ->willReturn ($ eventType );
78+ $ event = match ($ eventType ) {
79+ 'add ' => new CommentAddedEvent ($ comment ),
80+ 'pre_update ' => new BeforeCommentUpdatedEvent ($ comment ),
81+ 'update ' => new CommentUpdatedEvent ($ comment ),
82+ 'delete ' => new CommentDeletedEvent ($ comment ),
83+ };
8384
8485 /** @var INotification|MockObject $notification */
8586 $ notification = $ this ->createMock (INotification::class);
@@ -124,14 +125,12 @@ public function testEvaluateNoMentions(string $eventType): void {
124125 ->method ('getMentions ' )
125126 ->willReturn ([]);
126127
127- /** @var CommentsEvent|MockObject $event */
128- $ event = $ this ->createMock (CommentsEvent::class);
129- $ event ->expects ($ this ->once ())
130- ->method ('getComment ' )
131- ->willReturn ($ comment );
132- $ event ->expects (($ this ->any ()))
133- ->method (('getEvent ' ))
134- ->willReturn ($ eventType );
128+ $ event = match ($ eventType ) {
129+ 'add ' => new CommentAddedEvent ($ comment ),
130+ 'pre_update ' => new BeforeCommentUpdatedEvent ($ comment ),
131+ 'update ' => new CommentUpdatedEvent ($ comment ),
132+ 'delete ' => new CommentDeletedEvent ($ comment ),
133+ };
135134
136135 $ this ->notificationManager ->expects ($ this ->never ())
137136 ->method ('createNotification ' );
@@ -162,14 +161,7 @@ public function testEvaluateUserDoesNotExist(): void {
162161 ->method ('getId ' )
163162 ->willReturn ('1234 ' );
164163
165- /** @var CommentsEvent|MockObject $event */
166- $ event = $ this ->createMock (CommentsEvent::class);
167- $ event ->expects ($ this ->once ())
168- ->method ('getComment ' )
169- ->willReturn ($ comment );
170- $ event ->expects (($ this ->any ()))
171- ->method (('getEvent ' ))
172- ->willReturn (CommentsEvent::EVENT_ADD );
164+ $ event = new CommentAddedEvent ($ comment );
173165
174166 /** @var INotification|MockObject $notification */
175167 $ notification = $ this ->createMock (INotification::class);
0 commit comments