Skip to content

Commit

Permalink
pkp#9899 notification mocks added
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Sep 27, 2024
1 parent d66444f commit fc86044
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/jobs/email/EditorialReminderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,35 @@ public function register(\Pimple\Container $pimple)

app()->instance(EmailTemplateRepository::class, $emailTemplateRepoMock);

$notificationMock = Mockery::mock(\APP\notification\Notification::class)
->makePartial()
->shouldReceive([
'setData' => null,
'getContextId' => 0,
])
->withAnyArgs()
->getMock();

$notifiactionDaoMock = Mockery::mock(\PKP\notification\NotificationDAO::class)
->makePartial()
->shouldReceive([
'newDataObject' => $notificationMock,
'insertObject' => 0,
])
->withAnyArgs()
->getMock();

DAORegistry::registerDAO('NotificationDAO', $notifiactionDaoMock);

$notificationSettingsDaoMock = Mockery::mock(\PKP\notification\NotificationSettingsDAO::class)
->makePartial()
->shouldReceive('updateNotificationSetting')
->withAnyArgs()
->andReturn(null)
->getMock();

DAORegistry::registerDAO('NotificationSettingsDAO', $notificationSettingsDaoMock);

$this->assertNull($editorialReminderJob->handle());
}
}
29 changes: 29 additions & 0 deletions tests/jobs/notifications/NewAnnouncementNotifyUsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,35 @@ public function testRunSerializedJob(): void

app()->instance(UserRepository::class, $userRepoMock);

$notificationMock = Mockery::mock(\APP\notification\Notification::class)
->makePartial()
->shouldReceive([
'setData' => null,
'getContextId' => 0,
])
->withAnyArgs()
->getMock();

$notifiactionDaoMock = Mockery::mock(\PKP\notification\NotificationDAO::class)
->makePartial()
->shouldReceive([
'newDataObject' => $notificationMock,
'insertObject' => 0,
])
->withAnyArgs()
->getMock();

DAORegistry::registerDAO('NotificationDAO', $notifiactionDaoMock);

$notificationSettingsDaoMock = Mockery::mock(\PKP\notification\NotificationSettingsDAO::class)
->makePartial()
->shouldReceive('updateNotificationSetting')
->withAnyArgs()
->andReturn(null)
->getMock();

DAORegistry::registerDAO('NotificationSettingsDAO', $notificationSettingsDaoMock);

$this->assertNull($newAnnouncementNotifyUsersJob->handle());
}
}
27 changes: 27 additions & 0 deletions tests/jobs/notifications/StatisticsReportMailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,33 @@ public function register(\Pimple\Container $pimple)

app()->instance(UserRepository::class, $userRepoMock);

$notificationMock = Mockery::mock(\APP\notification\Notification::class)
->makePartial()
->shouldReceive('setData')
->withAnyArgs()
->andReturn(null)
->getMock();

$notifiactionDaoMock = Mockery::mock(\PKP\notification\NotificationDAO::class)
->makePartial()
->shouldReceive([
'newDataObject' => $notificationMock,
'insertObject' => 0,
])
->withAnyArgs()
->getMock();

DAORegistry::registerDAO('NotificationDAO', $notifiactionDaoMock);

$notificationSettingsDaoMock = Mockery::mock(\PKP\notification\NotificationSettingsDAO::class)
->makePartial()
->shouldReceive('updateNotificationSetting')
->withAnyArgs()
->andReturn(null)
->getMock();

DAORegistry::registerDAO('NotificationSettingsDAO', $notificationSettingsDaoMock);

$this->assertNull($statisticsReportMailJob->handle());
}
}
28 changes: 28 additions & 0 deletions tests/jobs/notifications/StatisticsReportNotifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace PKP\tests\jobs\notifications;

use Mockery;
use PKP\db\DAORegistry;
use APP\core\Application;
use PKP\tests\PKPTestCase;
use PKP\user\Repository as UserRepository;
Expand Down Expand Up @@ -76,6 +77,33 @@ public function testRunSerializedJob(): void

app()->instance(UserRepository::class, $userRepoMock);

$notificationMock = Mockery::mock(\APP\notification\Notification::class)
->makePartial()
->shouldReceive('setData')
->withAnyArgs()
->andReturn(null)
->getMock();

$notifiactionDaoMock = Mockery::mock(\PKP\notification\NotificationDAO::class)
->makePartial()
->shouldReceive([
'newDataObject' => $notificationMock,
'insertObject' => 0,
])
->withAnyArgs()
->getMock();

DAORegistry::registerDAO('NotificationDAO', $notifiactionDaoMock);

$notificationSettingsDaoMock = Mockery::mock(\PKP\notification\NotificationSettingsDAO::class)
->makePartial()
->shouldReceive('updateNotificationSetting')
->withAnyArgs()
->andReturn(null)
->getMock();

DAORegistry::registerDAO('NotificationSettingsDAO', $notificationSettingsDaoMock);

$this->assertNull($statisticsReportNotifyJob->handle());
}
}

0 comments on commit fc86044

Please sign in to comment.