Skip to content

Commit b667b70

Browse files
committed
MAGETWO-67626: Auto-generated classes behave differently in unit tests and application
- fixed failing unit tests
1 parent 82eb562 commit b667b70

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/Total/ShippingTest.php

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
namespace Magento\Sales\Test\Unit\Model\Order\Invoice\Total;
108

119
/**
@@ -37,11 +35,11 @@ protected function _getInvoiceCollection(array $invoicesData)
3735
),
3836
'calculatorFactory' => $this->getMock(
3937
\Magento\Framework\Math\CalculatorFactory::class,
40-
[],
41-
[],
42-
'',
43-
false
44-
),
38+
[],
39+
[],
40+
'',
41+
false
42+
),
4543
'invoiceItemCollectionFactory' => $this->getMock(
4644
\Magento\Sales\Model\ResourceModel\Order\Invoice\Item\CollectionFactory::class,
4745
[],
@@ -78,31 +76,32 @@ protected function _getInvoiceCollection(array $invoicesData)
7876
* @dataProvider collectDataProvider
7977
* @param array $prevInvoicesData
8078
* @param float $orderShipping
81-
* @param float $invoiceShipping
8279
* @param float $expectedShipping
8380
*/
84-
public function testCollect(array $prevInvoicesData, $orderShipping, $invoiceShipping, $expectedShipping)
81+
public function testCollect(array $prevInvoicesData, $orderShipping, $expectedShipping)
8582
{
8683
$order = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
8784
->disableOriginalConstructor()
8885
->getMock();
89-
$order->setData('shipping_amount', $orderShipping);
90-
$order->expects(
91-
$this->any()
92-
)->method(
93-
'getInvoiceCollection'
94-
)->will(
95-
$this->returnValue($this->_getInvoiceCollection($prevInvoicesData))
96-
);
97-
/** @var $invoice \Magento\Sales\Model\Order\Invoice|PHPUnit_Framework_MockObject_MockObject */
98-
$invoice = $this->getMock(\Magento\Sales\Model\Order\Invoice::class, ['_init', '__wakeup'], [], '', false);
99-
$invoice->setData('shipping_amount', $invoiceShipping);
100-
$invoice->setOrder($order);
86+
$order->expects($this->any())
87+
->method('getInvoiceCollection')
88+
->will($this->returnValue($this->_getInvoiceCollection($prevInvoicesData)));
89+
$order->expects($this->any())
90+
->method('getShippingAmount')
91+
->willReturn($orderShipping);
92+
/** @var $invoice \Magento\Sales\Model\Order\Invoice|\PHPUnit_Framework_MockObject_MockObject */
93+
$invoice = $this->getMockBuilder(\Magento\Sales\Model\Order\Invoice::class)
94+
->disableOriginalConstructor()
95+
->getMock();
96+
$invoice->expects($this->any())
97+
->method('getOrder')
98+
->willReturn($order);
99+
$invoice->expects($this->any())
100+
->method('setShippingAmount')
101+
->withConsecutive([0], [$expectedShipping]);
101102

102103
$total = new \Magento\Sales\Model\Order\Invoice\Total\Shipping();
103104
$total->collect($invoice);
104-
105-
$this->assertEquals($expectedShipping, $invoice->getShippingAmount());
106105
}
107106

108107
public static function collectDataProvider()
@@ -111,19 +110,16 @@ public static function collectDataProvider()
111110
'no previous invoices' => [
112111
'prevInvoicesData' => [[]],
113112
'orderShipping' => 10.00,
114-
'invoiceShipping' => 5.00,
115113
'expectedShipping' => 10.00,
116114
],
117115
'zero shipping in previous invoices' => [
118116
'prevInvoicesData' => [['shipping_amount' => '0.0000']],
119117
'orderShipping' => 10.00,
120-
'invoiceShipping' => 5.00,
121118
'expectedShipping' => 10.00,
122119
],
123120
'non-zero shipping in previous invoices' => [
124121
'prevInvoicesData' => [['shipping_amount' => '10.000']],
125122
'orderShipping' => 10.00,
126-
'invoiceShipping' => 5.00,
127123
'expectedShipping' => 0,
128124
]
129125
];

0 commit comments

Comments
 (0)