Skip to content

Commit 3f588c6

Browse files
aakimovomiroshnichenko
authored andcommitted
MAGETWO-71373: Cannot Install Magento without Some Modules
1 parent 30081f9 commit 3f588c6

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

lib/internal/Magento/Framework/EntityManager/OperationPool.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,28 @@
88

99
use Magento\Framework\ObjectManagerInterface as ObjectManager;
1010
use Magento\Framework\EntityManager\OperationInterface;
11+
use Magento\Framework\EntityManager\Operation\CheckIfExists;
12+
use Magento\Framework\EntityManager\Operation\Read;
13+
use Magento\Framework\EntityManager\Operation\Create;
14+
use Magento\Framework\EntityManager\Operation\Update;
15+
use Magento\Framework\EntityManager\Operation\Delete;
1116

1217
/**
1318
* Class OperationPool
1419
*/
1520
class OperationPool
1621
{
22+
/**
23+
* @var array
24+
*/
25+
private $defaultOperations = [
26+
'checkIfExists' => CheckIfExists::class,
27+
'read' => Read::class,
28+
'create' => Create::class,
29+
'update' => Update::class,
30+
'delete' => Delete::class,
31+
];
32+
1733
/**
1834
* @var array
1935
*/
@@ -31,10 +47,13 @@ class OperationPool
3147
*/
3248
public function __construct(
3349
ObjectManager $objectManager,
34-
$operations
50+
$operations = []
3551
) {
3652
$this->objectManager = $objectManager;
37-
$this->operations = $operations;
53+
$this->operations = array_replace_recursive(
54+
['default' => $this->defaultOperations],
55+
$operations
56+
);
3857
}
3958

4059
/**
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\EntityManager\Test\Unit;
7+
8+
use PHPUnit\Framework\TestCase;
9+
use Magento\Framework\ObjectManagerInterface;
10+
use Magento\Framework\EntityManager\OperationPool;
11+
12+
class OperationPoolTest extends TestCase
13+
{
14+
public function testGetOperationUsesDefaultValueForEntityThatDoesNotProvideCustomMapping()
15+
{
16+
$objectManagerMock = $this->createMock(ObjectManagerInterface::class);
17+
$operationPool = new OperationPool(
18+
$objectManagerMock,
19+
[]
20+
);
21+
22+
$objectManagerMock->expects($this->once())
23+
->method('get')
24+
->with('Magento\Framework\EntityManager\Operation\Read');
25+
$operationPool->getOperation('entity_type', 'read');
26+
}
27+
28+
public function testGetOperationUsesOverriddenDefaultValueForEntityThatDoesNotProvideCustomMapping()
29+
{
30+
$customReadOperation = 'CustomReadOperation';
31+
$objectManagerMock = $this->createMock(ObjectManagerInterface::class);
32+
$operationPool = new OperationPool(
33+
$objectManagerMock,
34+
[
35+
'default' => [
36+
'read' => $customReadOperation,
37+
'new' => 'CustomNewOperation',
38+
],
39+
]
40+
);
41+
42+
$objectManagerMock->expects($this->once())
43+
->method('get')
44+
->with($customReadOperation);
45+
$operationPool->getOperation('entity_type', 'read');
46+
}
47+
}

0 commit comments

Comments
 (0)