Skip to content

Commit c221127

Browse files
ENGCOM-6625: Prevent endless loop when duplicating product #25875
- Merge Pull Request #25875 from JeroenVanLeusden/magento2:JeroenVanLeusden-patch-4 - Merged commits: 1. 8e2959d 2. a027e87 3. 64cb774
2 parents f39d3bd + 64cb774 commit c221127

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed

app/code/Magento/Catalog/Model/Product/Copier.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ public function __construct(
5959
CopyConstructorInterface $copyConstructor,
6060
ProductFactory $productFactory,
6161
ScopeOverriddenValue $scopeOverriddenValue,
62-
OptionRepository $optionRepository = null,
63-
MetadataPool $metadataPool = null
62+
OptionRepository $optionRepository,
63+
MetadataPool $metadataPool
6464
) {
6565
$this->productFactory = $productFactory;
6666
$this->copyConstructor = $copyConstructor;
6767
$this->scopeOverriddenValue = $scopeOverriddenValue;
68-
$this->optionRepository = $optionRepository ?: ObjectManager::getInstance()->get(OptionRepository::class);
69-
$this->metadataPool = $metadataPool ?: ObjectManager::getInstance()->get(MetadataPool::class);
68+
$this->optionRepository = $optionRepository;
69+
$this->metadataPool = $metadataPool;
7070
}
7171

7272
/**

app/code/Magento/Catalog/Test/Unit/Model/Product/CopierTest.php

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ class CopierTest extends \PHPUnit\Framework\TestCase
1919
/**
2020
* @var \PHPUnit_Framework_MockObject_MockObject
2121
*/
22-
protected $optionRepositoryMock;
22+
private $optionRepositoryMock;
2323

2424
/**
2525
* @var Copier
2626
*/
27-
protected $_model;
27+
private $_model;
2828

2929
/**
3030
* @var \PHPUnit_Framework_MockObject_MockObject
3131
*/
32-
protected $copyConstructorMock;
32+
private $copyConstructorMock;
3333

3434
/**
3535
* @var \PHPUnit_Framework_MockObject_MockObject
3636
*/
37-
protected $productFactoryMock;
37+
private $productFactoryMock;
3838

3939
/**
4040
* @var \PHPUnit_Framework_MockObject_MockObject
@@ -44,12 +44,12 @@ class CopierTest extends \PHPUnit\Framework\TestCase
4444
/**
4545
* @var \PHPUnit_Framework_MockObject_MockObject
4646
*/
47-
protected $productMock;
47+
private $productMock;
4848

4949
/**
5050
* @var \PHPUnit_Framework_MockObject_MockObject
5151
*/
52-
protected $metadata;
52+
private $metadata;
5353

5454
protected function setUp()
5555
{
@@ -77,13 +77,10 @@ protected function setUp()
7777
$this->_model = new Copier(
7878
$this->copyConstructorMock,
7979
$this->productFactoryMock,
80-
$this->scopeOverriddenValueMock
80+
$this->scopeOverriddenValueMock,
81+
$this->optionRepositoryMock,
82+
$metadataPool
8183
);
82-
83-
$this->setProperties($this->_model, [
84-
'optionRepository' => $this->optionRepositoryMock,
85-
'metadataPool' => $metadataPool
86-
]);
8784
}
8885

8986
/**
@@ -340,20 +337,4 @@ public function testUrlAlreadyExistsExceptionWhileCopyStoresUrl()
340337
$this->expectException(\Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException::class);
341338
$this->_model->copy($this->productMock);
342339
}
343-
344-
/**
345-
* @param $object
346-
* @param array $properties
347-
*/
348-
private function setProperties($object, $properties = [])
349-
{
350-
$reflectionClass = new \ReflectionClass(get_class($object));
351-
foreach ($properties as $key => $value) {
352-
if ($reflectionClass->hasProperty($key)) {
353-
$reflectionProperty = $reflectionClass->getProperty($key);
354-
$reflectionProperty->setAccessible(true);
355-
$reflectionProperty->setValue($object, $value);
356-
}
357-
}
358-
}
359340
}

0 commit comments

Comments
 (0)