1818use OCP \Server ;
1919use PHPUnit \Framework \Attributes \DataProvider ;
2020use PHPUnit \Framework \MockObject \MockObject ;
21+ use Psr \Log \LoggerInterface ;
2122
2223final class ReminderServiceTest extends \OCA \Libresign \Tests \Unit \TestCase {
2324 protected IJobList |MockObject $ jobList ;
2425 protected IAppConfig $ appConfig ;
2526 protected IDateTimeZone $ dateTimeZone ;
26- protected ITimeFactory $ time ;
27+ protected ITimeFactory | MockObject $ time ;
2728 protected SignRequestMapper |MockObject $ signRequestMapper ;
2829 protected IdentifyMethodService |MockObject $ identifyMethodService ;
30+ protected LoggerInterface |MockObject $ logger ;
2931
3032 public function setUp (): void {
3133 $ this ->jobList = $ this ->createMock (IJobList::class);
3234 $ this ->appConfig = $ this ->getMockAppConfig ();
3335 $ this ->dateTimeZone = Server::get (IDateTimeZone::class);
34- $ this ->time = Server:: get (ITimeFactory::class);
36+ $ this ->time = $ this -> createMock (ITimeFactory::class);
3537 $ this ->signRequestMapper = $ this ->createMock (SignRequestMapper::class);
3638 $ this ->identifyMethodService = $ this ->createMock (IdentifyMethodService::class);
39+ $ this ->logger = $ this ->createMock (LoggerInterface::class);
3740 }
3841
3942 private function getService (array $ methods = []): ReminderService |MockObject {
@@ -46,6 +49,7 @@ private function getService(array $methods = []): ReminderService|MockObject {
4649 $ this ->time ,
4750 $ this ->signRequestMapper ,
4851 $ this ->identifyMethodService ,
52+ $ this ->logger ,
4953 ])
5054 ->onlyMethods ($ methods )
5155 ->getMock ();
@@ -57,6 +61,7 @@ private function getService(array $methods = []): ReminderService|MockObject {
5761 $ this ->time ,
5862 $ this ->signRequestMapper ,
5963 $ this ->identifyMethodService ,
64+ $ this ->logger ,
6065 );
6166 }
6267
@@ -105,7 +110,7 @@ public function testWillNotify(array $summarized, \DateTime $now, int $daysBefor
105110 }
106111
107112 public static function providerWillNotify (): array {
108- $ now = ( new DateTime ())-> setTime ( 12 , 0 );
113+ $ now = new DateTime (' 2025-10-09 12:00:00 ' , new \ DateTimeZone ( ' UTC ' ) );
109114
110115 return [
111116 'no notifications, should not send with all zero and null ' => [
@@ -327,6 +332,11 @@ public function testSave(
327332 string $ sendTimer ,
328333 array $ expected ,
329334 ): void {
335+ // Setup fixed time for consistent testing
336+ $ fixedTime = new DateTime ('2025-10-09 09:00:00 ' , new \DateTimeZone ('UTC ' ));
337+ $ this ->time ->method ('getDateTime ' )
338+ ->willReturn ($ fixedTime );
339+
330340 $ service = $ this ->getService ();
331341 $ actual = $ service ->save ($ daysBefore , $ daysBetween , $ max , $ sendTimer );
332342 $ this ->assertEquals ($ expected , $ actual );
@@ -347,7 +357,7 @@ public function testSave(
347357 }
348358
349359 public static function providerSave (): array {
350- $ now = (new DateTime ());
360+ $ now = (new DateTime (' 2025-10-09 09:00:00 ' , new \ DateTimeZone ( ' UTC ' ) ));
351361 return [
352362 [
353363 'daysBefore ' => 0 , 'daysBetween ' => 0 , 'max ' => 0 , 'sendTimer ' => '' ,
@@ -415,7 +425,7 @@ public static function providerSave(): array {
415425 'days_before ' => 1 ,
416426 'days_between ' => 1 ,
417427 'max ' => 1 ,
418- 'next_run ' => (clone $ now )->modify ( ' +1 day ' )-> setTime (10 , 0 ),
428+ 'next_run ' => (clone $ now )->setTime (10 , 0 ),
419429 'send_timer ' => '10:00 ' ,
420430 ],
421431 ],
@@ -425,17 +435,27 @@ public static function providerSave(): array {
425435 'days_before ' => 1 ,
426436 'days_between ' => 1 ,
427437 'max ' => 1 ,
428- 'next_run ' => (clone $ now )->modify ( ' +1 day ' )-> setTime (10 , 0 ),
438+ 'next_run ' => (clone $ now )->setTime (10 , 0 ),
429439 'send_timer ' => '10:00 ' ,
430440 ],
431441 ],
442+ [
443+ 'daysBefore ' => 1 , 'daysBetween ' => 1 , 'max ' => 1 , 'sendTimer ' => '08:05 ' ,
444+ 'expected ' => [
445+ 'days_before ' => 1 ,
446+ 'days_between ' => 1 ,
447+ 'max ' => 1 ,
448+ 'next_run ' => (clone $ now )->modify ('+1 day ' )->setTime (8 , 5 ),
449+ 'send_timer ' => '08:05 ' ,
450+ ],
451+ ],
432452 [
433453 'daysBefore ' => 1 , 'daysBetween ' => 1 , 'max ' => 1 , 'sendTimer ' => '11:05 ' ,
434454 'expected ' => [
435455 'days_before ' => 1 ,
436456 'days_between ' => 1 ,
437457 'max ' => 1 ,
438- 'next_run ' => (clone $ now )->modify ( ' +1 day ' )-> setTime (11 , 5 ),
458+ 'next_run ' => (clone $ now )->setTime (11 , 5 ),
439459 'send_timer ' => '11:05 ' ,
440460 ],
441461 ],
0 commit comments