Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ShipmentServiceTest.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class ShipmentServiceTest extends \PHPUnit\Framework\TestCase
14 {
21 
28 
34  protected $filterBuilderMock;
35 
41  protected $repositoryMock;
42 
48  protected $notifierMock;
49 
53  protected $shipmentService;
54 
58  protected function setUp()
59  {
60  $objectManager = new ObjectManagerHelper($this);
61 
62  $this->commentRepositoryMock = $this->getMockForAbstractClass(
63  \Magento\Sales\Api\ShipmentCommentRepositoryInterface::class,
64  ['getList'],
65  '',
66  false
67  );
68  $this->searchCriteriaBuilderMock = $this->createPartialMock(
69  \Magento\Framework\Api\SearchCriteriaBuilder::class,
70  ['create', 'addFilters']
71  );
72  $this->filterBuilderMock = $this->createPartialMock(
73  \Magento\Framework\Api\FilterBuilder::class,
74  ['setField', 'setValue', 'setConditionType', 'create']
75  );
76  $this->repositoryMock = $this->getMockForAbstractClass(
77  \Magento\Sales\Api\ShipmentRepositoryInterface::class,
78  ['get'],
79  '',
80  false
81  );
82  $this->notifierMock = $this->createPartialMock(\Magento\Shipping\Model\ShipmentNotifier::class, ['notify']);
83 
84  $this->shipmentService = $objectManager->getObject(
85  \Magento\Sales\Model\Service\ShipmentService::class,
86  [
87  'commentRepository' => $this->commentRepositoryMock,
88  'criteriaBuilder' => $this->searchCriteriaBuilderMock,
89  'filterBuilder' => $this->filterBuilderMock,
90  'repository' => $this->repositoryMock,
91  'notifier' => $this->notifierMock,
92  ]
93  );
94  }
95 
99  public function testGetLabel()
100  {
101  $id = 145;
102  $returnValue = 'return-value';
103 
104  $shipmentMock = $this->createPartialMock(\Magento\Sales\Model\Order\Shipment::class, ['getShippingLabel']);
105 
106  $this->repositoryMock->expects($this->once())
107  ->method('get')
108  ->with($id)
109  ->will($this->returnValue($shipmentMock));
110  $shipmentMock->expects($this->once())
111  ->method('getShippingLabel')
112  ->will($this->returnValue($returnValue));
113 
114  $this->assertEquals($returnValue, $this->shipmentService->getLabel($id));
115  }
116 
120  public function testGetCommentsList()
121  {
122  $id = 25;
123  $returnValue = 'return-value';
124 
125  $filterMock = $this->createMock(\Magento\Framework\Api\Filter::class);
126  $searchCriteriaMock = $this->createMock(\Magento\Framework\Api\SearchCriteria::class);
127 
128  $this->filterBuilderMock->expects($this->once())
129  ->method('setField')
130  ->with('parent_id')
131  ->will($this->returnSelf());
132  $this->filterBuilderMock->expects($this->once())
133  ->method('setValue')
134  ->with($id)
135  ->will($this->returnSelf());
136  $this->filterBuilderMock->expects($this->once())
137  ->method('setConditionType')
138  ->with('eq')
139  ->will($this->returnSelf());
140  $this->filterBuilderMock->expects($this->once())
141  ->method('create')
142  ->will($this->returnValue($filterMock));
143  $this->searchCriteriaBuilderMock->expects($this->once())
144  ->method('addFilters')
145  ->with([$filterMock]);
146  $this->searchCriteriaBuilderMock->expects($this->once())
147  ->method('create')
148  ->will($this->returnValue($searchCriteriaMock));
149  $this->commentRepositoryMock->expects($this->once())
150  ->method('getList')
151  ->with($searchCriteriaMock)
152  ->will($this->returnValue($returnValue));
153 
154  $this->assertEquals($returnValue, $this->shipmentService->getCommentsList($id));
155  }
156 
160  public function testNotify()
161  {
162  $id = 123;
163  $returnValue = 'return-value';
164 
165  $modelMock = $this->getMockForAbstractClass(
166  \Magento\Sales\Model\AbstractModel::class,
167  [],
168  '',
169  false
170  );
171 
172  $this->repositoryMock->expects($this->once())
173  ->method('get')
174  ->with($id)
175  ->will($this->returnValue($modelMock));
176  $this->notifierMock->expects($this->once())
177  ->method('notify')
178  ->with($modelMock)
179  ->will($this->returnValue($returnValue));
180 
181  $this->assertEquals($returnValue, $this->shipmentService->notify($id));
182  }
183 }
$objectManager
Definition: bootstrap.php:17
$id
Definition: fieldset.phtml:14