Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DismissTest.php
Go to the documentation of this file.
1 <?php
7 
14 
15 class DismissTest extends \PHPUnit\Framework\TestCase
16 {
20  private $model;
21 
25  private $notificationManagementMock;
26 
30  private $requestMock;
31 
35  private $resultFactoryMock;
36 
40  private $jsonResultMock;
41 
42  protected function setUp()
43  {
44  $objectManager = new ObjectManager($this);
45  $this->notificationManagementMock = $this->createMock(BulkNotificationManagement::class);
46  $this->requestMock = $this->createMock(RequestInterface::class);
47  $this->resultFactoryMock = $this->createPartialMock(ResultFactory::class, ['create']);
48 
49  $this->jsonResultMock = $this->createMock(Json::class);
50 
51  $this->model = $objectManager->getObject(
52  Dismiss::class,
53  [
54  'notificationManagement' => $this->notificationManagementMock,
55  'request' => $this->requestMock,
56  'resultFactory' => $this->resultFactoryMock,
57  ]
58  );
59  }
60 
61  public function testExecute()
62  {
63  $bulkUuids = ['49da7406-1ec3-4100-95ae-9654c83a6801'];
64 
65  $this->requestMock->expects($this->any())
66  ->method('getParam')
67  ->with('uuid', [])
68  ->willReturn($bulkUuids);
69 
70  $this->notificationManagementMock->expects($this->once())
71  ->method('acknowledgeBulks')
72  ->with($bulkUuids)
73  ->willReturn(true);
74 
75  $this->resultFactoryMock->expects($this->once())
76  ->method('create')
77  ->with(ResultFactory::TYPE_JSON, [])
78  ->willReturn($this->jsonResultMock);
79 
80  $this->assertEquals($this->jsonResultMock, $this->model->execute());
81  }
82 
84  {
85  $bulkUuids = ['49da7406-1ec3-4100-95ae-9654c83a6801'];
86 
87  $this->requestMock->expects($this->any())
88  ->method('getParam')
89  ->with('uuid', [])
90  ->willReturn($bulkUuids);
91 
92  $this->resultFactoryMock->expects($this->once())
93  ->method('create')
94  ->with(ResultFactory::TYPE_JSON, [])
95  ->willReturn($this->jsonResultMock);
96 
97  $this->notificationManagementMock->expects($this->once())
98  ->method('acknowledgeBulks')
99  ->with($bulkUuids)
100  ->willReturn(false);
101 
102  $this->jsonResultMock->expects($this->once())
103  ->method('setHttpResponseCode')
104  ->with(400);
105 
106  $this->assertEquals($this->jsonResultMock, $this->model->execute());
107  }
108 }
$objectManager
Definition: bootstrap.php:17