Skip to content

Commit 2c8b332

Browse files
committed
MC-37364: Unit Test and JSUnit Test fails to start on Magento composer 2.4.0
1 parent f8dd0b5 commit 2c8b332

File tree

19 files changed

+320
-93
lines changed

19 files changed

+320
-93
lines changed

app/code/Magento/CatalogImportExport/Test/Unit/Model/Export/ProductTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ protected function setUp(): void
172172

173173
$this->productFactory = $this->getMockBuilder(
174174
\Magento\Catalog\Model\ResourceModel\ProductFactory::class
175-
)->addMethods(['getTypeId'])
175+
)->disableOriginalConstructor()
176+
->addMethods(['getTypeId'])
176177
->onlyMethods(['create'])
177178
->getMock();
178179

app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ protected function setUp(): void
148148
'importCustomerAddressData',
149149
'save',
150150
'getShippingRateByCode',
151-
'getShippingMethod'
151+
'getShippingMethod',
152152
]
153153
)
154154
->disableOriginalConstructor()
@@ -167,7 +167,7 @@ protected function setUp(): void
167167
'collectTotals',
168168
'getExtensionAttributes',
169169
'setExtensionAttributes',
170-
'setBillingAddress'
170+
'setBillingAddress',
171171
]
172172
)
173173
->disableOriginalConstructor()
@@ -238,9 +238,7 @@ private function setShippingAssignmentsMocks($shippingMethod): void
238238
->willReturn(null);
239239
$this->shippingAddressMock->expects($this->once())
240240
->method('setLimitCarrier');
241-
$this->cartExtensionMock = $this->getMockBuilder(CartExtension::class)
242-
->addMethods(['getShippingAssignments', 'setShippingAssignments'])
243-
->getMock();
241+
$this->cartExtensionMock = $this->getCartExtensionMock();
244242
$this->cartExtensionFactoryMock->expects($this->once())
245243
->method('create')
246244
->willReturn($this->cartExtensionMock);
@@ -622,4 +620,21 @@ public function testSaveAddressInformation(): void
622620
$this->model->saveAddressInformation($cartId, $addressInformationMock)
623621
);
624622
}
623+
624+
/**
625+
* Build cart extension mock.
626+
*
627+
* @return MockObject
628+
*/
629+
private function getCartExtensionMock(): MockObject
630+
{
631+
$mockBuilder = $this->getMockBuilder(CartExtension::class);
632+
try {
633+
$mockBuilder->addMethods(['getShippingAssignments', 'setShippingAssignments']);
634+
} catch (\RuntimeException $e) {
635+
// CartExtension already generated.
636+
}
637+
638+
return $mockBuilder->getMock();
639+
}
625640
}

app/code/Magento/CheckoutAgreements/Test/Unit/Model/Checkout/Plugin/GuestValidationTest.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ protected function setUp(): void
7878
$this->subjectMock = $this->getMockForAbstractClass(GuestPaymentInformationManagementInterface::class);
7979
$this->paymentMock = $this->getMockForAbstractClass(PaymentInterface::class);
8080
$this->addressMock = $this->getMockForAbstractClass(AddressInterface::class);
81-
$this->extensionAttributesMock = $this->getMockBuilder(PaymentExtension::class)
82-
->addMethods(['getAgreementIds'])
83-
->getMock();
81+
$this->extensionAttributesMock = $this->getPaymentExtension();
8482
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
8583
$this->checkoutAgreementsListMock = $this->createMock(
8684
CheckoutAgreementsListInterface::class
@@ -165,4 +163,21 @@ public function testBeforeSavePaymentInformationAndPlaceOrderIfAgreementsNotVali
165163
"The order wasn't placed. First, agree to the terms and conditions, then try placing your order again."
166164
);
167165
}
166+
167+
/**
168+
* Build payment extension mock.
169+
*
170+
* @return MockObject
171+
*/
172+
private function getPaymentExtension(): MockObject
173+
{
174+
$mockBuilder = $this->getMockBuilder(PaymentExtension::class);
175+
try {
176+
$mockBuilder->addMethods(['getAgreementIds']);
177+
} catch (\RuntimeException $e) {
178+
// Payment extension already generated.
179+
}
180+
181+
return $mockBuilder->getMock();
182+
}
168183
}

app/code/Magento/CheckoutAgreements/Test/Unit/Model/Checkout/Plugin/ValidationTest.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ protected function setUp(): void
9696
->disableOriginalConstructor()
9797
->getMock();
9898
$this->quoteRepositoryMock = $this->getMockForAbstractClass(CartRepositoryInterface::class);
99-
$this->extensionAttributesMock = $this->getMockBuilder(PaymentExtension::class)
100-
->addMethods(['getAgreementIds'])
101-
->getMock();
99+
$this->extensionAttributesMock = $this->getPaymentExtension();
102100
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
103101
$this->checkoutAgreementsListMock = $this->createMock(
104102
CheckoutAgreementsListInterface::class
@@ -232,4 +230,21 @@ public function testBeforeSavePaymentInformation()
232230
->willReturn($this->extensionAttributesMock);
233231
$this->model->beforeSavePaymentInformation($this->subjectMock, $cartId, $this->paymentMock, $this->addressMock);
234232
}
233+
234+
/**
235+
* Build payment extension mock.
236+
*
237+
* @return MockObject
238+
*/
239+
private function getPaymentExtension(): MockObject
240+
{
241+
$mockBuilder = $this->getMockBuilder(PaymentExtension::class);
242+
try {
243+
$mockBuilder->addMethods(['getAgreementIds']);
244+
} catch (\RuntimeException $e) {
245+
// Payment extension already generated.
246+
}
247+
248+
return $mockBuilder->getMock();
249+
}
235250
}

app/code/Magento/Customer/Test/Unit/Model/Renderer/RegionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ function (array $attributes) use ($elementMock): string {
6666
}
6767
);
6868
$countryMock = $this->getMockBuilder(AbstractElement::class)
69-
->addMethods(['getValue', 'serialize'])
69+
->onlyMethods(['serialize'])
70+
->addMethods(['getValue'])
7071
->disableOriginalConstructor()
7172
->getMockForAbstractClass();
7273
$countryMock->method('serialize')->willReturnCallback(

app/code/Magento/Downloadable/Test/Unit/Model/Link/UpdateHandlerTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected function setUp(): void
5656
->getMockForAbstractClass();
5757
$this->linkMock = $this->getMockBuilder(LinkInterface::class)
5858
->getMock();
59-
$this->productExtensionMock = $this->createMock(ProductExtensionInterface::class);
59+
$this->productExtensionMock = $this->getProductExtensionMock();
6060
$this->productExtensionMock->expects($this->once())
6161
->method('getDownloadableProductLinks')
6262
->willReturn([$this->linkMock]);
@@ -145,4 +145,22 @@ public function testExecuteNonDownloadable(): void
145145

146146
$this->assertEquals($this->entityMock, $this->model->execute($this->entityMock));
147147
}
148+
149+
/**
150+
* Build product extension mock.
151+
*
152+
* @return MockObject
153+
*/
154+
private function getProductExtensionMock(): MockObject
155+
{
156+
$mockBuilder = $this->getMockBuilder(ProductExtensionInterface::class)
157+
->disableOriginalConstructor();
158+
try {
159+
$mockBuilder->addMethods(['getDownloadableProductLinks']);
160+
} catch (\RuntimeException $e) {
161+
// ProductExtension already generated.
162+
}
163+
164+
return $mockBuilder->getMockForAbstractClass();
165+
}
148166
}

app/code/Magento/Downloadable/Test/Unit/Model/Quote/Item/CartItemProcessorTest.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,12 @@ public function testProcessProductOptions()
170170
$this->optionFactoryMock->expects($this->once())->method('create')->willReturn($productOptionMock);
171171
$productOptionMock->expects($this->once())->method('getExtensionAttributes')->willReturn(null);
172172

173-
$extAttributeMock = $this->getMockBuilder(ProductOptionExtension::class)
174-
->addMethods(['setDownloadableOption'])
175-
->getMock();
173+
$extAttributeMock = $this->getProductOptionExtensionMock();
176174

177175
$this->objectHelperMock->expects($this->once())->method('populateWithArray')->with(
178176
$downloadableOptionMock,
179177
[
180-
'downloadable_links' => $downloadableLinks
178+
'downloadable_links' => $downloadableLinks,
181179
],
182180
DownloadableOptionInterface::class
183181
);
@@ -206,9 +204,7 @@ public function testProcessProductOptionsWhenItemDoesNotHaveDownloadableLinks()
206204
->method('getOptionByCode')
207205
->with('downloadable_link_ids');
208206

209-
$extAttributeMock = $this->getMockBuilder(ProductOptionExtension::class)
210-
->addMethods(['setDownloadableOption'])
211-
->getMock();
207+
$extAttributeMock = $this->getProductOptionExtensionMock();
212208
$productOptionMock = $this->getMockForAbstractClass(ProductOptionInterface::class);
213209
$productOptionMock->expects($this->any())
214210
->method('getExtensionAttributes')
@@ -228,7 +224,7 @@ public function testProcessProductOptionsWhenItemDoesNotHaveDownloadableLinks()
228224
$this->objectHelperMock->expects($this->once())->method('populateWithArray')->with(
229225
$downloadableOptionMock,
230226
[
231-
'downloadable_links' => $downloadableLinks
227+
'downloadable_links' => $downloadableLinks,
232228
],
233229
DownloadableOptionInterface::class
234230
);
@@ -243,4 +239,21 @@ public function testProcessProductOptionsWhenItemDoesNotHaveDownloadableLinks()
243239

244240
$this->assertEquals($cartItemMock, $this->model->processOptions($cartItemMock));
245241
}
242+
243+
/**
244+
* Build product option extension mock.
245+
*
246+
* @return MockObject
247+
*/
248+
private function getProductOptionExtensionMock(): MockObject
249+
{
250+
$mockBuilder = $this->getMockBuilder(ProductOptionExtension::class);
251+
try {
252+
$mockBuilder->addMethods(['setDownloadableOption']);
253+
} catch (\RuntimeException $e) {
254+
// ProductOptionExtension already generated.
255+
}
256+
257+
return $mockBuilder->getMock();
258+
}
246259
}

app/code/Magento/Downloadable/Test/Unit/Model/Sample/UpdateHandlerTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected function setUp(): void
5656
->getMockForAbstractClass();
5757
$this->sampleMock = $this->getMockBuilder(SampleInterface::class)
5858
->getMock();
59-
$this->productExtensionMock = $this->createMock(ProductExtensionInterface::class);
59+
$this->productExtensionMock = $this->getProductExtensionMock();
6060
$this->productExtensionMock//->expects($this->once())
6161
->method('getDownloadableProductSamples')
6262
->willReturn([$this->sampleMock]);
@@ -145,4 +145,22 @@ public function testExecuteNonDownloadable(): void
145145

146146
$this->assertEquals($this->entityMock, $this->model->execute($this->entityMock));
147147
}
148+
149+
/**
150+
* Build product extension mock.
151+
*
152+
* @return MockObject
153+
*/
154+
private function getProductExtensionMock(): MockObject
155+
{
156+
$mockBuilder = $this->getMockBuilder(ProductExtensionInterface::class)
157+
->disableOriginalConstructor();
158+
try {
159+
$mockBuilder->addMethods(['getDownloadableProductSamples']);
160+
} catch (\RuntimeException $e) {
161+
// Product extension already generated.
162+
}
163+
164+
return $mockBuilder->getMockForAbstractClass();
165+
}
148166
}

app/code/Magento/Downloadable/Test/Unit/Observer/IsAllowedGuestCheckoutObserverTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ protected function setUp(): void
9191
->getMock();
9292

9393
$this->storeMock = $this->getMockBuilder(DataObject::class)
94+
->addMethods(['getId'])
9495
->disableOriginalConstructor()
9596
->getMock();
9697

9798
$this->storeManagerMock = $this->getMockForAbstractClass(StoreManagerInterface::class);
98-
$this->storeManagerMock
99-
->method('getStore')
100-
->with(self::STUB_STORE_ID)
99+
$this->storeManagerMock->method('getStore')
100+
->with($this->storeMock)
101101
->willReturn($this->storeMock);
102102

103103
$this->isAllowedGuestCheckoutObserver = (new ObjectManagerHelper($this))

app/code/Magento/GiftMessage/Test/Unit/Model/Plugin/OrderGetTest.php

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,14 @@ protected function setUp(): void
106106
$this->orderMock = $this->createMock(
107107
OrderInterface::class
108108
);
109-
$this->orderExtensionMock = $this->getMockBuilder(OrderExtension::class)
110-
->addMethods(['getGiftMessage', 'setGiftMessage'])
111-
->getMock();
109+
$this->orderExtensionMock = $this->getOrderExtensionMock();
112110
$this->giftMessageMock = $this->createMock(
113111
MessageInterface::class
114112
);
115113
$this->orderItemMock = $this->createMock(
116114
OrderItemInterface::class
117115
);
118-
$this->orderItemExtensionMock = $this->getMockBuilder(OrderItemExtension::class)
119-
->addMethods(['setGiftMessage', 'getGiftMessage'])
120-
->getMock();
116+
$this->orderItemExtensionMock = $this->getOrderItemExtensionMock();
121117
$this->orderRepositoryMock = $this->createMock(
122118
\Magento\Sales\Api\OrderRepositoryInterface::class
123119
);
@@ -272,4 +268,38 @@ public function testAfterGetList()
272268
$this->collectionMock->expects($this->once())->method('getItems')->willReturn([$this->orderMock]);
273269
$this->plugin->afterGetList($this->orderRepositoryMock, $this->collectionMock);
274270
}
271+
272+
/**
273+
* Build order extension mock.
274+
*
275+
* @return MockObject
276+
*/
277+
private function getOrderExtensionMock(): MockObject
278+
{
279+
$mockObject = $this->getMockBuilder(OrderExtension::class);
280+
try {
281+
$mockObject->addMethods(['getGiftMessage', 'setGiftMessage']);
282+
} catch (\RuntimeException $e) {
283+
// Order extension already generated.
284+
}
285+
286+
return $mockObject->getMock();
287+
}
288+
289+
/**
290+
* Build order item extension mock.
291+
*
292+
* @return MockObject
293+
*/
294+
private function getOrderItemExtensionMock(): MockObject
295+
{
296+
$mockObject = $this->getMockBuilder(OrderItemExtension::class);
297+
try {
298+
$mockObject->addMethods(['getGiftMessage', 'setGiftMessage']);
299+
} catch (\RuntimeException $e) {
300+
// Order extension already generated.
301+
}
302+
303+
return $mockObject->getMock();
304+
}
275305
}

0 commit comments

Comments
 (0)