Skip to content

Commit e952481

Browse files
author
Dmytro Voskoboinikov
committed
MAGETWO-44741: Bugfixes PR preparation and processing
1 parent 6ecc7df commit e952481

File tree

8 files changed

+75
-134
lines changed

8 files changed

+75
-134
lines changed

app/code/Magento/Paypal/Test/Unit/Model/ResourceModel/Billing/AgreementTest.php

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

7-
namespace Magento\Paypal\Test\Unit\Model\ResourceModel;
7+
namespace Magento\Paypal\Test\Unit\Model\ResourceModel\Billing;
88

99
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1010

@@ -96,7 +96,7 @@ public function testAddOrdersFilter()
9696
->withConsecutive(
9797
['pbao.agreement_id IN(?)', [100]],
9898
['main_table.entity_id IN (?)', [500]]
99-
)
99+
)
100100
->willReturnSelf();
101101
$this->connectionMock->expects($this->once())
102102
->method('fetchCol')

app/code/Magento/Sales/Test/Unit/Model/InvoiceRepositoryTest.php

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,18 @@ public function testGet()
5151
$entity = $this->getMockBuilder('Magento\Sales\Model\Order\Invoice')
5252
->disableOriginalConstructor()
5353
->getMock();
54+
$entity->expects($this->once())
55+
->method('load')
56+
->with($id)
57+
->willReturn($entity);
5458
$entity->expects($this->once())
5559
->method('getEntityId')
5660
->willReturn($id);
61+
5762
$this->invoiceMetadata->expects($this->once())
5863
->method('getNewInstance')
5964
->willReturn($entity);
6065

61-
$mapper = $this->getMockBuilder('Magento\Sales\Model\ResourceModel\Order\Invoice')
62-
->disableOriginalConstructor()
63-
->getMock();
64-
$mapper->expects($this->once())
65-
->method('load')
66-
->with($entity, $id);
67-
68-
$this->invoiceMetadata->expects($this->any())
69-
->method('getMapper')
70-
->willReturn($mapper);
7166
$this->assertEquals($entity, $this->invoice->get($id));
7267
}
7368

@@ -91,23 +86,18 @@ public function testGetEntityNoId()
9186
$entity = $this->getMockBuilder('Magento\Sales\Model\Order\Invoice')
9287
->disableOriginalConstructor()
9388
->getMock();
89+
$entity->expects($this->once())
90+
->method('load')
91+
->with($id)
92+
->willReturn($entity);
9493
$entity->expects($this->once())
9594
->method('getEntityId')
9695
->willReturn(null);
96+
9797
$this->invoiceMetadata->expects($this->once())
9898
->method('getNewInstance')
9999
->willReturn($entity);
100100

101-
$mapper = $this->getMockBuilder('Magento\Sales\Model\ResourceModel\Order\Invoice')
102-
->disableOriginalConstructor()
103-
->getMock();
104-
$mapper->expects($this->once())
105-
->method('load')
106-
->with($entity, $id);
107-
108-
$this->invoiceMetadata->expects($this->any())
109-
->method('getMapper')
110-
->willReturn($mapper);
111101
$this->assertNull($entity, $this->invoice->get($id));
112102
}
113103

@@ -199,24 +189,21 @@ public function testDeleteById()
199189
$entity = $this->getMockBuilder('Magento\Sales\Model\Order\Invoice')
200190
->disableOriginalConstructor()
201191
->getMock();
192+
$entity->expects($this->once())
193+
->method('load')
194+
->with($id)
195+
->willReturn($entity);
202196
$entity->expects($this->any())
203197
->method('getEntityId')
204198
->willReturn($id);
199+
205200
$this->invoiceMetadata->expects($this->once())
206201
->method('getNewInstance')
207202
->willReturn($entity);
208203

209204
$mapper = $this->getMockBuilder('Magento\Sales\Model\ResourceModel\Order\Invoice')
210205
->disableOriginalConstructor()
211206
->getMock();
212-
$mapper->expects($this->once())
213-
->method('load')
214-
->with($entity, $id);
215-
216-
$this->invoiceMetadata->expects($this->any())
217-
->method('getMapper')
218-
->willReturn($mapper);
219-
220207
$mapper->expects($this->once())
221208
->method('delete')
222209
->with($entity);

app/code/Magento/Sales/Test/Unit/Model/Order/AddressRepositoryTest.php

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,35 +76,22 @@ public function testGet($id, $entityId)
7676
} else {
7777
$address = $this->getMock(
7878
'Magento\Sales\Model\Order\Address',
79-
['getEntityId'],
79+
['load', 'getEntityId'],
8080
[],
8181
'',
8282
false
8383
);
84+
$address->expects($this->once())
85+
->method('load')
86+
->with($id)
87+
->willReturn($address);
8488
$address->expects($this->once())
8589
->method('getEntityId')
8690
->willReturn($entityId);
8791

88-
$mapper = $this->getMockForAbstractClass(
89-
'Magento\Framework\Model\ResourceModel\Db\AbstractDb',
90-
[],
91-
'',
92-
false,
93-
true,
94-
true,
95-
['load']
96-
);
97-
$mapper->expects($this->once())
98-
->method('load')
99-
->with($address, $id)
100-
->willReturnSelf();
101-
10292
$this->metadata->expects($this->once())
10393
->method('getNewInstance')
10494
->willReturn($address);
105-
$this->metadata->expects($this->once())
106-
->method('getMapper')
107-
->willReturn($mapper);
10895

10996
if (!$entityId) {
11097
$this->setExpectedException(
@@ -115,14 +102,19 @@ public function testGet($id, $entityId)
115102
} else {
116103
$this->assertEquals($address, $this->subject->get($id));
117104

118-
$mapper->expects($this->never())
119-
->method('load');
105+
$address->expects($this->never())
106+
->method('load')
107+
->with($id)
108+
->willReturn($address);
109+
$address->expects($this->never())
110+
->method('getEntityId')
111+
->willReturn($entityId);
120112

121113
$this->metadata->expects($this->never())
122-
->method('getNewInstance');
123-
$this->metadata->expects($this->never())
124-
->method('getMapper');
114+
->method('getNewInstance')
115+
->willReturn($address);
125116

117+
// Retrieve Address from registry.
126118
$this->assertEquals($address, $this->subject->get($id));
127119
}
128120
}

app/code/Magento/Sales/Test/Unit/Model/Order/CreditmemoRepositoryTest.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,18 @@ public function testGet()
5555
$entity = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo')
5656
->disableOriginalConstructor()
5757
->getMock();
58+
$entity->expects($this->once())
59+
->method('load')
60+
->with($id)
61+
->willReturn($entity);
5862
$entity->expects($this->once())
5963
->method('getEntityId')
6064
->willReturn($id);
65+
6166
$this->metadataMock->expects($this->once())
6267
->method('getNewInstance')
6368
->willReturn($entity);
6469

65-
$mapper = $this->getMockBuilder('Magento\Sales\Model\ResourceModel\Order\Creditmemo')
66-
->disableOriginalConstructor()
67-
->getMock();
68-
$mapper->expects($this->once())
69-
->method('load')
70-
->with($entity, $id);
71-
72-
$this->metadataMock->expects($this->any())
73-
->method('getMapper')
74-
->willReturn($mapper);
7570
$this->assertEquals($entity, $this->creditmemo->get($id));
7671
//retrieve entity from registry
7772
$this->assertEquals($entity, $this->creditmemo->get($id));
@@ -96,23 +91,18 @@ public function testGetEntityNoId()
9691
$entity = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo')
9792
->disableOriginalConstructor()
9893
->getMock();
94+
$entity->expects($this->once())
95+
->method('load')
96+
->with($id)
97+
->willReturn($entity);
9998
$entity->expects($this->once())
10099
->method('getEntityId')
101100
->willReturn(null);
101+
102102
$this->metadataMock->expects($this->once())
103103
->method('getNewInstance')
104104
->willReturn($entity);
105105

106-
$mapper = $this->getMockBuilder('Magento\Sales\Model\ResourceModel\Order\Creditmemo')
107-
->disableOriginalConstructor()
108-
->getMock();
109-
$mapper->expects($this->once())
110-
->method('load')
111-
->with($entity, $id);
112-
113-
$this->metadataMock->expects($this->any())
114-
->method('getMapper')
115-
->willReturn($mapper);
116106
$this->assertNull($entity, $this->creditmemo->get($id));
117107
}
118108

app/code/Magento/Sales/Test/Unit/Model/Order/ItemRepositoryTest.php

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,17 @@ public function testGetEmptyEntity()
105105
$orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item')
106106
->disableOriginalConstructor()
107107
->getMock();
108+
$orderItemMock->expects($this->once())
109+
->method('load')
110+
->with($orderItemId)
111+
->willReturn($orderItemMock);
108112
$orderItemMock->expects($this->once())
109113
->method('getItemId')
110114
->willReturn(null);
111115

112-
$orderItemResourceMock = $this->getMockBuilder('Magento\Framework\Model\ResourceModel\Db\AbstractDb')
113-
->disableOriginalConstructor()
114-
->getMock();
115-
$orderItemResourceMock->expects($this->once())
116-
->method('load')
117-
->with($orderItemMock, $orderItemId)
118-
->willReturnSelf();
119-
120116
$this->metadata->expects($this->once())
121117
->method('getNewInstance')
122118
->willReturn($orderItemMock);
123-
$this->metadata->expects($this->once())
124-
->method('getMapper')
125-
->willReturn($orderItemResourceMock);
126119

127120
$model = new ItemRepository(
128121
$this->objectFactory,
@@ -146,24 +139,17 @@ public function testGet()
146139
$productOption = $this->getProductOptionMock();
147140
$orderItemMock = $this->getOrderMock($productType, $productOption);
148141

142+
$orderItemMock->expects($this->once())
143+
->method('load')
144+
->with($orderItemId)
145+
->willReturn($orderItemMock);
149146
$orderItemMock->expects($this->once())
150147
->method('getItemId')
151148
->willReturn($orderItemId);
152149

153-
$orderItemResourceMock = $this->getMockBuilder('Magento\Framework\Model\ResourceModel\Db\AbstractDb')
154-
->disableOriginalConstructor()
155-
->getMock();
156-
$orderItemResourceMock->expects($this->once())
157-
->method('load')
158-
->with($orderItemMock, $orderItemId)
159-
->willReturnSelf();
160-
161150
$this->metadata->expects($this->once())
162151
->method('getNewInstance')
163152
->willReturn($orderItemMock);
164-
$this->metadata->expects($this->once())
165-
->method('getMapper')
166-
->willReturn($orderItemResourceMock);
167153

168154
$model = $this->getModel($orderItemMock, $productType);
169155
$this->assertSame($orderItemMock, $model->get($orderItemId));
@@ -245,6 +231,10 @@ public function testDeleteById()
245231
$orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item')
246232
->disableOriginalConstructor()
247233
->getMock();
234+
$orderItemMock->expects($this->once())
235+
->method('load')
236+
->with($orderItemId)
237+
->willReturn($orderItemMock);
248238
$orderItemMock->expects($this->once())
249239
->method('getItemId')
250240
->willReturn($orderItemId);
@@ -262,15 +252,11 @@ public function testDeleteById()
262252
->method('delete')
263253
->with($orderItemMock)
264254
->willReturnSelf();
265-
$orderItemResourceMock->expects($this->once())
266-
->method('load')
267-
->with($orderItemMock, $orderItemId)
268-
->willReturnSelf();
269255

270256
$this->metadata->expects($this->once())
271257
->method('getNewInstance')
272258
->willReturn($orderItemMock);
273-
$this->metadata->expects($this->exactly(2))
259+
$this->metadata->expects($this->exactly(1))
274260
->method('getMapper')
275261
->willReturn($orderItemResourceMock);
276262

app/code/Magento/Sales/Test/Unit/Model/Order/Payment/RepositoryTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ public function testGet()
139139
{
140140
$paymentId = 1;
141141
$payment = $this->mockPayment($paymentId);
142+
$payment->expects($this->any())->method('load')->with($paymentId)->willReturn($payment);
142143
$this->metaData->expects($this->once())->method('getNewInstance')->willReturn($payment);
143-
$this->metaData->expects($this->once())->method('getMapper')->willReturn($this->paymentResource);
144-
$this->paymentResource->expects($this->once())->method('load')->with($payment, $paymentId);
145144
$this->assertSame($payment, $this->repository->get($paymentId));
146145
}
147146

@@ -164,9 +163,8 @@ public function testGetNoSuchEntity()
164163
{
165164
$paymentId = 1;
166165
$payment = $this->mockPayment(null);
166+
$payment->expects($this->any())->method('load')->with($paymentId)->willReturn($payment);
167167
$this->metaData->expects($this->once())->method('getNewInstance')->willReturn($payment);
168-
$this->metaData->expects($this->once())->method('getMapper')->willReturn($this->paymentResource);
169-
$this->paymentResource->expects($this->once())->method('load')->with($payment, $paymentId);
170168
$this->assertSame($payment, $this->repository->get($paymentId));
171169
}
172170

@@ -187,6 +185,7 @@ protected function mockPayment($id = false)
187185
'',
188186
false
189187
);
188+
190189
if ($id !== false) {
191190
$payment->expects($this->once())->method('getId')->willReturn($id);
192191
}

app/code/Magento/Sales/Test/Unit/Model/Order/Payment/Transaction/RepositoryTest.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,9 @@ public function testGet()
210210
{
211211
$transactionId = 12;
212212
$transaction = $this->mockTransaction($transactionId);
213+
$transaction->expects($this->any())->method('load')->with($transactionId)->willReturn($transaction);
213214
$this->entityStorage->method('has')->with($transactionId)->willReturn(false);
214215
$this->metaData->expects($this->once())->method('getNewInstance')->willReturn($transaction);
215-
$this->metaData->expects($this->once())->method('getMapper')->willReturn($this->transactionResource);
216-
$this->transactionResource->expects($this->once())->method('load')->with($transaction, $transactionId);
217216
$this->entityStorage->expects($this->once())->method('add')->with($transaction);
218217
$this->entityStorage->expects($this->once())->method('get')->with($transactionId)->willReturn($transaction);
219218
$this->assertSame($transaction, $this->repository->get($transactionId));
@@ -240,13 +239,9 @@ public function testGetNoSuchEntity()
240239
$transactionId = null;
241240
$transactionIdFromArgument = 12;
242241
$transaction = $this->mockTransaction($transactionId);
242+
$transaction->expects($this->any())->method('load')->with(12)->willReturn($transaction);
243243
$this->entityStorage->method('has')->with($transactionIdFromArgument)->willReturn(false);
244244
$this->metaData->expects($this->once())->method('getNewInstance')->willReturn($transaction);
245-
$this->metaData->expects($this->once())->method('getMapper')->willReturn($this->transactionResource);
246-
$this->transactionResource->expects($this->once())->method('load')->with(
247-
$transaction,
248-
$transactionIdFromArgument
249-
);
250245
$this->entityStorage->expects($this->never())->method('add');
251246
$this->entityStorage->expects($this->never())->method('get');
252247
$this->assertSame($transaction, $this->repository->get(12));

0 commit comments

Comments
 (0)