Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NotificationServiceTest.php
Go to the documentation of this file.
1 <?php
11 
12 class NotificationServiceTest extends \PHPUnit\Framework\TestCase
13 {
20  protected function _getServiceInstanceForMarkAsReadTest($notificationId)
21  {
26  $notificationFactory = $this->createPartialMock(
27  \Magento\AdminNotification\Model\InboxFactory::class,
28  ['create']
29  );
30  $notification = $this->createPartialMock(
31  \Magento\AdminNotification\Model\Inbox::class,
32  ['load', 'getId', 'save', 'setIsRead', '__sleep', '__wakeup']
33  );
34  $notification->expects($this->once())->method('load')->with($notificationId)->will($this->returnSelf());
35  $notification->expects($this->once())->method('getId')->will($this->returnValue($notificationId));
36 
37  // when notification Id is valid, add additional expectations
38  if ($notificationId) {
39  $notification->expects($this->once())->method('save')->will($this->returnSelf());
40  $notification->expects($this->once())->method('setIsRead')->with(1)->will($this->returnSelf());
41  }
42 
43  $notificationFactory->expects($this->once())->method('create')->will($this->returnValue($notification));
44  return new \Magento\AdminNotification\Model\NotificationService($notificationFactory);
45  }
46 
47  public function testMarkAsRead()
48  {
49  $notificationId = 1;
50  $service = $this->_getServiceInstanceForMarkAsReadTest($notificationId);
51  $service->markAsRead($notificationId);
52  }
53 
59  {
60  $notificationId = null;
61  $service = $this->_getServiceInstanceForMarkAsReadTest($notificationId);
62  $service->markAsRead($notificationId);
63  }
64 }