Skip to content

Commit 6aacfa3

Browse files
author
vtymchynskyi
committed
MAGETWO-35385: Fatal error when trying to send notify customer by email about shipment
1 parent 504bad6 commit 6aacfa3

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

app/code/Magento/Shipping/Test/Unit/Controller/Adminhtml/Order/Shipment/AddCommentTest.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ class AddCommentTest extends \PHPUnit_Framework_TestCase
6060
*/
6161
protected $resultLayoutFactoryMock;
6262

63+
/**
64+
* @var \Magento\Framework\View\Result\Layout|\PHPUnit_Framework_MockObject_MockObject
65+
*/
66+
protected $resultLayoutMock;
67+
6368
/**
6469
* @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
6570
*/
@@ -109,7 +114,7 @@ protected function setUp()
109114
);
110115
$this->resultLayoutFactoryMock = $this->getMock(
111116
'Magento\Framework\View\Result\LayoutFactory',
112-
[],
117+
['create'],
113118
[],
114119
'',
115120
false
@@ -202,15 +207,19 @@ public function testExecute()
202207
$shipment = [];
203208
$tracking = [];
204209

205-
$layoutMock = $this->getMock('Magento\Framework\View\Layout', ['getBlock'], [], '', false);
206-
$blockMock = $this->getMock('Magento\Shipping\Block\Adminhtml\View\Comments', ['toHtml'], [], '', false);
210+
$this->resultLayoutMock = $this->getMock(
211+
'Magento\Framework\View\Result\Layout',
212+
['getBlock', 'getDefaultLayoutHandle', 'addDefaultHandle', 'getLayout'],
213+
[],
214+
'',
215+
false
216+
);
207217

208218
$this->requestMock->expects($this->once())->method('setParam')->with('shipment_id', $shipmentId);
209219
$this->requestMock->expects($this->once())
210220
->method('getPost')
211221
->with('comment')
212222
->will($this->returnValue($data));
213-
$this->titleMock->expects($this->once())->method('prepend');
214223
$this->requestMock->expects($this->any())
215224
->method('getParam')
216225
->will(
@@ -234,10 +243,13 @@ public function testExecute()
234243
$this->shipmentMock->expects($this->once())->method('addComment');
235244
$this->shipmentSenderMock->expects($this->once())->method('send');
236245
$this->shipmentMock->expects($this->once())->method('save');
237-
$this->viewInterfaceMock->expects($this->once())->method('loadLayout')->with(false);
238-
$this->viewInterfaceMock->expects($this->once())->method('getLayout')->will($this->returnValue($layoutMock));
239-
$layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($blockMock));
240-
$blockMock->expects($this->once())->method('toHtml')->will($this->returnValue($result));
246+
$layoutMock = $this->getMock('Magento\Framework\View\Layout', ['getBlock'], [], '', false);
247+
$blockMock = $this->getMock('Magento\Shipping\Block\Adminhtml\View\Comments', ['toHtml'], [], '', false);
248+
$blockMock->expects($this->once())->method('toHtml')->willReturn($result);
249+
$layoutMock->expects($this->once())->method('getBlock')->with('shipment_comments')->willReturn($blockMock);
250+
$this->resultLayoutMock->expects($this->once())->method('getLayout')->willReturn($layoutMock);
251+
$this->resultLayoutMock->expects($this->once())->method('addDefaultHandle');
252+
$this->resultLayoutFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->resultLayoutMock));
241253
$this->responseMock->expects($this->once())->method('setBody')->with($result);
242254

243255
$this->assertNull($this->controller->execute());

0 commit comments

Comments
 (0)