File tree Expand file tree Collapse file tree 2 files changed +68
-2
lines changed
lib/internal/Magento/Framework/EntityManager Expand file tree Collapse file tree 2 files changed +68
-2
lines changed Original file line number Diff line number Diff line change 8
8
9
9
use Magento \Framework \ObjectManagerInterface as ObjectManager ;
10
10
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 ;
11
16
12
17
/**
13
18
* Class OperationPool
14
19
*/
15
20
class OperationPool
16
21
{
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
+
17
33
/**
18
34
* @var array
19
35
*/
@@ -31,10 +47,13 @@ class OperationPool
31
47
*/
32
48
public function __construct (
33
49
ObjectManager $ objectManager ,
34
- $ operations
50
+ $ operations = []
35
51
) {
36
52
$ this ->objectManager = $ objectManager ;
37
- $ this ->operations = $ operations ;
53
+ $ this ->operations = array_replace_recursive (
54
+ ['default ' => $ this ->defaultOperations ],
55
+ $ operations
56
+ );
38
57
}
39
58
40
59
/**
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments