55
66namespace Tests \Icinga \Module \Notifications \Forms ;
77
8+ use ArrayIterator ;
89use DateTime ;
910use Icinga \Module \Notifications \Forms \EventRuleConfigElements \ConfigProviderInterface ;
1011use Icinga \Module \Notifications \Forms \EventRuleConfigForm ;
1920use ipl \Orm \ResultSet ;
2021use ipl \Sql \Connection ;
2122use ipl \Web \Url ;
23+ use PDOStatement ;
2224use PHPUnit \Framework \TestCase ;
2325use Psr \Http \Message \ServerRequestInterface ;
2426
@@ -152,21 +154,27 @@ public function testLoadAndStorage(): void
152154 $ firstRuleEscalationRecipientMock ->expects ($ this ->once ())
153155 ->method ('columns ' )
154156 ->with (['id ' , 'contact_id ' , 'contactgroup_id ' , 'schedule_id ' , 'channel_id ' ])
155- ->willReturn ([
157+ ->willReturnSelf ();
158+
159+ $ firstRuleEscalationRecipientMock ->method ('getIterator ' )
160+ ->willReturn (new ArrayIterator ([
156161 (new RuleEscalationRecipient ())->setProperties ([
157162 'id ' => 1 ,
158163 'contact_id ' => 1 ,
159164 'contactgroup_id ' => null ,
160165 'schedule_id ' => null ,
161166 'channel_id ' => 1
162167 ])
163- ]);
168+ ])) ;
164169
165170 $ secondRuleEscalationRecipientMock = $ this ->createMock (Query::class);
166171 $ secondRuleEscalationRecipientMock ->expects ($ this ->once ())
167172 ->method ('columns ' )
168173 ->with (['id ' , 'contact_id ' , 'contactgroup_id ' , 'schedule_id ' , 'channel_id ' ])
169- ->willReturn ([
174+ ->willReturnSelf ();
175+
176+ $ secondRuleEscalationRecipientMock ->method ('getIterator ' )
177+ ->willReturn (new ArrayIterator ([
170178 (new RuleEscalationRecipient ())->setProperties ([
171179 'id ' => null ,
172180 'contact_id ' => null ,
@@ -181,7 +189,7 @@ public function testLoadAndStorage(): void
181189 'schedule_id ' => 1 ,
182190 'channel_id ' => 1
183191 ])
184- ]);
192+ ])) ;
185193
186194 $ ruleEscalationMock = $ this ->createMock (Query::class);
187195 $ ruleEscalationMock ->expects ($ this ->once ())
@@ -190,7 +198,7 @@ public function testLoadAndStorage(): void
190198 ->willReturnSelf ();
191199
192200 $ queryResult = new ResultSet (
193- new \ ArrayIterator ([
201+ new ArrayIterator ([
194202 (new RuleEscalation ())->setProperties ([
195203 'id ' => 1 ,
196204 'condition ' => null ,
@@ -271,6 +279,8 @@ public function testLoadAndStorage(): void
271279 } else {
272280 $ this ->fail (sprintf ('Unexpected table %s ' , $ table ));
273281 }
282+
283+ return $ this ->createStub (PDOStatement::class);
274284 });
275285
276286 $ databaseMock ->expects ($ this ->once ())
@@ -355,6 +365,8 @@ public function testLoadAndStorage(): void
355365 } else {
356366 $ this ->fail (sprintf ('Unexpected table %s ' , $ table ));
357367 }
368+
369+ return $ this ->createStub (PDOStatement::class);
358370 });
359371
360372 $ form = new EventRuleConfigForm ($ providerMock , $ this ->createStub (Url::class));
@@ -425,15 +437,18 @@ public function testNoChangesAlsoCauseNoUpdates(): void
425437 $ escalationRecipientMock ->expects ($ this ->once ())
426438 ->method ('columns ' )
427439 ->with (['id ' , 'contact_id ' , 'contactgroup_id ' , 'schedule_id ' , 'channel_id ' ])
428- ->willReturn ([
440+ ->willReturnSelf ();
441+
442+ $ escalationRecipientMock ->method ('getIterator ' )
443+ ->willReturn (new ArrayIterator ([
429444 (new RuleEscalationRecipient ())->setProperties ([
430445 'id ' => 1 ,
431446 'contact_id ' => 1 ,
432447 'contactgroup_id ' => null ,
433448 'schedule_id ' => null ,
434449 'channel_id ' => 1
435450 ])
436- ]);
451+ ])) ;
437452
438453 $ ruleEscalationMock = $ this ->createMock (Query::class);
439454 $ ruleEscalationMock ->expects ($ this ->once ())
@@ -442,7 +457,7 @@ public function testNoChangesAlsoCauseNoUpdates(): void
442457 ->willReturnSelf ();
443458
444459 $ queryResult = new ResultSet (
445- new \ ArrayIterator ([
460+ new ArrayIterator ([
446461 (new RuleEscalation ())->setProperties ([
447462 'id ' => 1 ,
448463 'condition ' => null ,
@@ -538,15 +553,18 @@ public function testIfARuleChangesOnlyTheRuleItselfIsUpdated(): void
538553 $ escalationRecipientMock ->expects ($ this ->once ())
539554 ->method ('columns ' )
540555 ->with (['id ' , 'contact_id ' , 'contactgroup_id ' , 'schedule_id ' , 'channel_id ' ])
541- ->willReturn ([
556+ ->willReturnSelf ();
557+
558+ $ escalationRecipientMock ->method ('getIterator ' )
559+ ->willReturn (new ArrayIterator ([
542560 (new RuleEscalationRecipient ())->setProperties ([
543561 'id ' => 1 ,
544562 'contact_id ' => 1 ,
545563 'contactgroup_id ' => null ,
546564 'schedule_id ' => null ,
547565 'channel_id ' => 1
548566 ])
549- ]);
567+ ])) ;
550568
551569 $ ruleEscalationMock = $ this ->createMock (Query::class);
552570 $ ruleEscalationMock ->expects ($ this ->once ())
@@ -555,7 +573,7 @@ public function testIfARuleChangesOnlyTheRuleItselfIsUpdated(): void
555573 ->willReturnSelf ();
556574
557575 $ queryResult = new ResultSet (
558- new \ ArrayIterator ([
576+ new ArrayIterator ([
559577 (new RuleEscalation ())->setProperties ([
560578 'id ' => 1 ,
561579 'condition ' => null ,
@@ -595,6 +613,8 @@ public function testIfARuleChangesOnlyTheRuleItselfIsUpdated(): void
595613 ],
596614 $ data
597615 );
616+
617+ return $ this ->createStub (PDOStatement::class);
598618 });
599619 $ databaseMock ->expects ($ this ->never ())
600620 ->method ('insert ' );
@@ -667,15 +687,18 @@ public function testIfARuleChangesOnlyTheEscalationIsUpdated(): void
667687 $ escalationRecipientMock ->expects ($ this ->once ())
668688 ->method ('columns ' )
669689 ->with (['id ' , 'contact_id ' , 'contactgroup_id ' , 'schedule_id ' , 'channel_id ' ])
670- ->willReturn ([
690+ ->willReturnSelf ();
691+
692+ $ escalationRecipientMock ->method ('getIterator ' )
693+ ->willReturn (new ArrayIterator ([
671694 (new RuleEscalationRecipient ())->setProperties ([
672695 'id ' => 1 ,
673696 'contact_id ' => 1 ,
674697 'contactgroup_id ' => null ,
675698 'schedule_id ' => null ,
676699 'channel_id ' => 1
677700 ])
678- ]);
701+ ])) ;
679702
680703 $ ruleEscalationMock = $ this ->createMock (Query::class);
681704 $ ruleEscalationMock ->expects ($ this ->once ())
@@ -684,7 +707,7 @@ public function testIfARuleChangesOnlyTheEscalationIsUpdated(): void
684707 ->willReturnSelf ();
685708
686709 $ queryResult = new ResultSet (
687- new \ ArrayIterator ([
710+ new ArrayIterator ([
688711 (new RuleEscalation ())->setProperties ([
689712 'id ' => 1 ,
690713 'condition ' => 'incident_severity>=crit&incident_age>5m ' ,
@@ -727,6 +750,8 @@ public function testIfARuleChangesOnlyTheEscalationIsUpdated(): void
727750 ],
728751 $ data
729752 );
753+
754+ return $ this ->createStub (PDOStatement::class);
730755 });
731756 $ databaseMock ->expects ($ this ->never ())
732757 ->method ('insert ' );
@@ -801,15 +826,18 @@ public function testIfARuleChangesOnlyTheEscalationRecipientIsUpdated(): void
801826 $ escalationRecipientMock ->expects ($ this ->once ())
802827 ->method ('columns ' )
803828 ->with (['id ' , 'contact_id ' , 'contactgroup_id ' , 'schedule_id ' , 'channel_id ' ])
804- ->willReturn ([
829+ ->willReturnSelf ();
830+
831+ $ escalationRecipientMock ->method ('getIterator ' )
832+ ->willReturn (new ArrayIterator ([
805833 (new RuleEscalationRecipient ())->setProperties ([
806834 'id ' => 1 ,
807835 'contact_id ' => null ,
808836 'contactgroup_id ' => 1 ,
809837 'schedule_id ' => null ,
810838 'channel_id ' => null
811839 ])
812- ]);
840+ ])) ;
813841
814842 $ ruleEscalationMock = $ this ->createMock (Query::class);
815843 $ ruleEscalationMock ->expects ($ this ->once ())
@@ -818,7 +846,7 @@ public function testIfARuleChangesOnlyTheEscalationRecipientIsUpdated(): void
818846 ->willReturnSelf ();
819847
820848 $ queryResult = new ResultSet (
821- new \ ArrayIterator ([
849+ new ArrayIterator ([
822850 (new RuleEscalation ())->setProperties ([
823851 'id ' => 1 ,
824852 'condition ' => null ,
@@ -860,6 +888,8 @@ public function testIfARuleChangesOnlyTheEscalationRecipientIsUpdated(): void
860888 ],
861889 $ data
862890 );
891+
892+ return $ this ->createStub (PDOStatement::class);
863893 });
864894 $ databaseMock ->expects ($ this ->never ())
865895 ->method ('insert ' );
0 commit comments