Skip to content

Commit 728edb7

Browse files
committed
MC-42430: Integration B2B test runs Jenkins agent out of memory
1 parent bd27efb commit 728edb7

File tree

9 files changed

+86
-103
lines changed

9 files changed

+86
-103
lines changed

dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ protected function tearDown(): void
8484
$this->_request = null;
8585
$this->_response = null;
8686
$this->_objectManager = null;
87+
88+
parent::tearDown();
89+
90+
// Release all objects saved in test class properties
91+
$reflection = new \ReflectionObject($this);
92+
foreach ($reflection->getProperties() as $property) {
93+
if (!$property->isStatic() && 0 !== strpos($property->getDeclaringClass()->getName(), 'PHPUnit')) {
94+
$property->setAccessible(true);
95+
$property->setValue($this, null);
96+
}
97+
}
8798
}
8899

89100
/**

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Save/CreateCustomOptionsTest.php

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,6 @@ class CreateCustomOptionsTest extends AbstractBackendController
2828
*/
2929
protected $productSku = 'simple';
3030

31-
/**
32-
* @var ProductRepositoryInterface
33-
*/
34-
private $productRepository;
35-
36-
/**
37-
* @var ProductCustomOptionRepositoryInterface
38-
*/
39-
private $optionRepository;
40-
41-
/**
42-
* @inheritDoc
43-
*/
44-
protected function setUp(): void
45-
{
46-
parent::setUp();
47-
48-
$this->productRepository = $this->_objectManager->create(ProductRepositoryInterface::class);
49-
$this->optionRepository = $this->_objectManager->create(ProductCustomOptionRepositoryInterface::class);
50-
}
51-
5231
/**
5332
* Test add to product custom option with type "field".
5433
*
@@ -61,14 +40,15 @@ protected function setUp(): void
6140
public function testSaveCustomOptionWithTypeField(array $productPostData): void
6241
{
6342
$this->getRequest()->setPostValue($productPostData);
64-
$product = $this->productRepository->get($this->productSku);
43+
$product = $this->_objectManager->get(ProductRepositoryInterface::class)->get($this->productSku);
6544
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
6645
$this->dispatch('backend/catalog/product/save/id/' . $product->getEntityId());
6746
$this->assertSessionMessages(
6847
$this->containsEqual('You saved the product.'),
6948
MessageInterface::TYPE_SUCCESS
7049
);
71-
$productOptions = $this->optionRepository->getProductOptions($product);
50+
$productOptions = $this->_objectManager->get(ProductCustomOptionRepositoryInterface::class)
51+
->getProductOptions($product);
7252
$this->assertCount(2, $productOptions);
7353
foreach ($productOptions as $customOption) {
7454
$postOptionData = $productPostData['product']['options'][$customOption->getTitle()] ?? null;

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Save/DeleteCustomOptionsTest.php

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,6 @@ class DeleteCustomOptionsTest extends AbstractBackendController
3030
*/
3131
protected $productSku = 'simple';
3232

33-
/**
34-
* @var ProductRepositoryInterface
35-
*/
36-
private $productRepository;
37-
38-
/**
39-
* @var ProductCustomOptionRepositoryInterface
40-
*/
41-
private $optionRepository;
42-
43-
/**
44-
* @var ProductCustomOptionInterfaceFactory
45-
*/
46-
private $optionRepositoryFactory;
47-
48-
/**
49-
* @inheritdoc
50-
*/
51-
protected function setUp(): void
52-
{
53-
parent::setUp();
54-
55-
$this->productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
56-
$this->optionRepository = $this->_objectManager->get(ProductCustomOptionRepositoryInterface::class);
57-
$this->optionRepositoryFactory = $this->_objectManager->get(ProductCustomOptionInterfaceFactory::class);
58-
}
5933

6034
/**
6135
* Test delete custom option with type "field".
@@ -67,18 +41,24 @@ protected function setUp(): void
6741
*/
6842
public function testDeleteCustomOptionWithTypeField(array $optionData): void
6943
{
70-
$product = $this->productRepository->get($this->productSku);
44+
$productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
45+
$product = $productRepository->get($this->productSku);
7146
/** @var ProductCustomOptionInterface $option */
72-
$option = $this->optionRepositoryFactory->create(['data' => $optionData]);
47+
$option = $this->_objectManager->get(ProductCustomOptionInterfaceFactory::class)
48+
->create(['data' => $optionData]);
7349
$option->setProductSku($product->getSku());
7450
$product->setOptions([$option]);
75-
$this->productRepository->save($product);
51+
$productRepository->save($product);
7652
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
7753
$this->dispatch('backend/catalog/product/save/id/' . $product->getEntityId());
7854
$this->assertSessionMessages(
7955
$this->equalTo([(string)__('You saved the product.')]),
8056
MessageInterface::TYPE_SUCCESS
8157
);
82-
$this->assertCount(0, $this->optionRepository->getProductOptions($product));
58+
$this->assertCount(
59+
0,
60+
$this->_objectManager->get(ProductCustomOptionRepositoryInterface::class)
61+
->getProductOptions($product)
62+
);
8363
}
8464
}

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Save/UpdateCustomOptionsTest.php

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,6 @@ class UpdateCustomOptionsTest extends AbstractBackendController
3131
*/
3232
protected $productSku = 'simple';
3333

34-
/**
35-
* @var ProductRepositoryInterface
36-
*/
37-
private $productRepository;
38-
39-
/**
40-
* @var ProductCustomOptionRepositoryInterface
41-
*/
42-
private $optionRepository;
43-
44-
/**
45-
* @var ProductCustomOptionInterfaceFactory
46-
*/
47-
private $optionRepositoryFactory;
48-
49-
/**
50-
* @inheritdoc
51-
*/
52-
protected function setUp(): void
53-
{
54-
parent::setUp();
55-
56-
$this->productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
57-
$this->optionRepository = $this->_objectManager->get(ProductCustomOptionRepositoryInterface::class);
58-
$this->optionRepositoryFactory = $this->_objectManager->get(ProductCustomOptionInterfaceFactory::class);
59-
}
60-
6134
/**
6235
* Test add to product custom option with type "field".
6336
*
@@ -69,13 +42,16 @@ protected function setUp(): void
6942
*/
7043
public function testUpdateCustomOptionWithTypeField(array $optionData, array $updateData): void
7144
{
72-
$product = $this->productRepository->get($this->productSku);
45+
$productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
46+
$optionRepository = $this->_objectManager->get(ProductCustomOptionRepositoryInterface::class);
47+
$product = $productRepository->get($this->productSku);
7348
/** @var ProductCustomOptionInterface|Option $option */
74-
$option = $this->optionRepositoryFactory->create(['data' => $optionData]);
49+
$option = $this->_objectManager->get(ProductCustomOptionInterfaceFactory::class)
50+
->create(['data' => $optionData]);
7551
$option->setProductSku($product->getSku());
7652
$product->setOptions([$option]);
77-
$this->productRepository->save($product);
78-
$currentProductOptions = $this->optionRepository->getProductOptions($product);
53+
$productRepository->save($product);
54+
$currentProductOptions = $optionRepository->getProductOptions($product);
7955
$this->assertCount(1, $currentProductOptions);
8056
/** @var ProductCustomOptionInterface $currentOption */
8157
$currentOption = reset($currentProductOptions);
@@ -119,7 +95,7 @@ public function testUpdateCustomOptionWithTypeField(array $optionData, array $up
11995
$this->containsEqual('You saved the product.'),
12096
MessageInterface::TYPE_SUCCESS
12197
);
122-
$updatedOptions = $this->optionRepository->getProductOptions($product);
98+
$updatedOptions = $optionRepository->getProductOptions($product);
12399
$this->assertCount(1, $updatedOptions);
124100
/** @var ProductCustomOptionInterface|Option $updatedOption */
125101
$updatedOption = reset($updatedOptions);

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Attribute/CreateOptionsTest.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,15 @@
2222
*/
2323
class CreateOptionsTest extends AbstractBackendController
2424
{
25-
/** @var ProductRepositoryInterface */
26-
private $productRepository;
27-
28-
/** @var SerializerInterface */
29-
private $json;
30-
31-
/** @var ProductAttributeRepositoryInterface */
32-
private $attributeRepository;
33-
3425
/**
3526
* @inheritdoc
3627
*/
3728
protected function setUp(): void
3829
{
3930
parent::setUp();
4031

41-
$this->productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
42-
$this->productRepository->cleanCache();
43-
$this->json = $this->_objectManager->get(SerializerInterface::class);
44-
$this->attributeRepository = $this->_objectManager->get(ProductAttributeRepositoryInterface::class);
32+
$productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
33+
$productRepository->cleanCache();
4534
}
4635

4736
/**
@@ -52,7 +41,8 @@ protected function setUp(): void
5241
public function testAddAlreadyAddedOption(): void
5342
{
5443
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
55-
$attribute = $this->attributeRepository->get('test_configurable');
44+
$attribute = $this->_objectManager->get(ProductAttributeRepositoryInterface::class)
45+
->get('test_configurable');
5646
$this->getRequest()->setParams([
5747
'options' => [
5848
[
@@ -63,7 +53,8 @@ public function testAddAlreadyAddedOption(): void
6353
],
6454
]);
6555
$this->dispatch('backend/catalog/product_attribute/createOptions');
66-
$responseBody = $this->json->unserialize($this->getResponse()->getBody());
56+
$responseBody = $this->_objectManager->get(SerializerInterface::class)
57+
->unserialize($this->getResponse()->getBody());
6758
$this->assertNotEmpty($responseBody);
6859
$this->assertStringContainsString(
6960
(string)__('The value of attribute ""%1"" must be unique', $attribute->getAttributeCode()),

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Initialization/HelperTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ protected function setUp(): void
9696
parent::setUp();
9797
$this->objectManager = Bootstrap::getObjectManager();
9898
$this->request = $this->objectManager->get(RequestInterface::class);
99-
$this->helper = $this->objectManager->create(Helper::class);
99+
$this->helper = $this->objectManager->get(Helper::class);
100100
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
101101
$this->productRepository->cleanCache();
102102
$this->productResource =$this->objectManager->get(ProductResource::class);
103-
$this->productAttributeRepository = $this->objectManager->create(ProductAttributeRepositoryInterface::class);
103+
$this->productAttributeRepository = $this->objectManager->get(ProductAttributeRepositoryInterface::class);
104104
$this->jsonSerializer = $this->objectManager->get(SerializerInterface::class);
105105
$this->searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
106106
$this->config = $this->objectManager->get(Config::class);
@@ -366,4 +366,19 @@ private function updateChildProductsImages(array $imageNames): void
366366
$this->productResource->save($simpleProduct);
367367
}
368368
}
369+
370+
/**
371+
* @inheritDoc
372+
*/
373+
protected function tearDown(): void
374+
{
375+
parent::tearDown();
376+
$reflection = new \ReflectionObject($this);
377+
foreach ($reflection->getProperties() as $property) {
378+
if (!$property->isStatic() && 0 !== strpos($property->getDeclaringClass()->getName(), 'PHPUnit')) {
379+
$property->setAccessible(true);
380+
$property->setValue($this, null);
381+
}
382+
}
383+
}
369384
}

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Controller/Adminhtml/ProductTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected function setUp(): void
6464
parent::setUp();
6565
$this->productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
6666
$this->productRepository->cleanCache();
67-
$this->productAttributeRepository = $this->_objectManager->create(ProductAttributeRepositoryInterface::class);
67+
$this->productAttributeRepository = $this->_objectManager->get(ProductAttributeRepositoryInterface::class);
6868
$this->registry = $this->_objectManager->get(Registry::class);
6969
$this->jsonSerializer = $this->_objectManager->get(SerializerInterface::class);
7070
$this->eavConfig = $this->_objectManager->get(Config::class);

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Category/ProductIndexerTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,19 @@ private function getCategories()
218218

219219
return array_slice($result, 0, 4);
220220
}
221+
222+
/**
223+
* @inheritDoc
224+
*/
225+
protected function tearDown(): void
226+
{
227+
parent::tearDown();
228+
$reflection = new \ReflectionObject($this);
229+
foreach ($reflection->getProperties() as $property) {
230+
if (!$property->isStatic() && 0 !== strpos($property->getDeclaringClass()->getName(), 'PHPUnit')) {
231+
$property->setAccessible(true);
232+
$property->setValue($this, null);
233+
}
234+
}
235+
}
221236
}

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/FindByUrlRewriteTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,19 @@ private function getProductIdsBySkus(array $productsData): array
264264

265265
return $this->productResource->getProductsIdsBySkus($skus);
266266
}
267+
268+
/**
269+
* @inheritDoc
270+
*/
271+
protected function tearDown(): void
272+
{
273+
parent::tearDown();
274+
$reflection = new \ReflectionObject($this);
275+
foreach ($reflection->getProperties() as $property) {
276+
if (!$property->isStatic() && 0 !== strpos($property->getDeclaringClass()->getName(), 'PHPUnit')) {
277+
$property->setAccessible(true);
278+
$property->setValue($this, null);
279+
}
280+
}
281+
}
267282
}

0 commit comments

Comments
 (0)