@@ -21,48 +21,94 @@ class ReadHandlerTest extends \PHPUnit_Framework_TestCase
21
21
*/
22
22
private $ metadataPoolMock ;
23
23
24
+ /**
25
+ * @var EntityMetadataInterface|\PHPUnit_Framework_MockObject_MockObject
26
+ */
27
+ private $ metadataMock ;
28
+
24
29
/**
25
30
* @var \Magento\Eav\Model\ResourceModel\ReadHandler
26
31
*/
27
32
private $ readHandler ;
28
33
34
+ /**
35
+ * @var \Magento\Framework\Model\Entity\ScopeResolver|\PHPUnit_Framework_MockObject_MockObject
36
+ */
37
+ private $ scopeResolverMock ;
38
+
29
39
protected function setUp ()
30
40
{
31
- $ this ->metadataPoolMock = $ this ->getMockBuilder (\Magento \Framework \EntityManager \MetadataPool::class)
41
+ $ objectManager = new ObjectManager ($ this );
42
+ $ args = $ objectManager ->getConstructArguments (\Magento \Eav \Model \ResourceModel \ReadHandler::class);
43
+ $ this ->metadataPoolMock = $ args ['metadataPool ' ];
44
+ $ this ->metadataMock = $ this ->getMockBuilder (EntityMetadataInterface::class)
32
45
->disableOriginalConstructor ()
33
46
->getMock ();
34
- $ this ->configMock = $ this ->getMockBuilder (\Magento \Eav \Model \Config::class)
35
- ->disableOriginalConstructor ()
36
- ->getMock ();
37
- $ this ->readHandler = (new ObjectManager ($ this ))->getObject (
38
- \Magento \Eav \Model \ResourceModel \ReadHandler::class,
39
- [
40
- 'metadataPool ' => $ this ->metadataPoolMock ,
41
- 'config ' => $ this ->configMock ,
42
- ]
43
- );
47
+ $ this ->metadataPoolMock ->expects ($ this ->any ())
48
+ ->method ('getMetadata ' )
49
+ ->willReturn ($ this ->metadataMock );
50
+ $ this ->configMock = $ args ['config ' ];
51
+ $ this ->scopeResolverMock = $ args ['scopeResolver ' ];
52
+ $ this ->scopeResolverMock ->method ('getEntityContext ' )
53
+ ->willReturn ([]);
54
+
55
+ $ this ->readHandler = $ objectManager ->getObject (\Magento \Eav \Model \ResourceModel \ReadHandler::class, $ args );
44
56
}
45
57
46
58
/**
47
59
* @param string $eavEntityType
48
60
* @param int $callNum
49
61
* @param array $expected
50
- * @dataProvider getAttributesDataProvider
62
+ * @param bool $isStatic
63
+ * @dataProvider executeDataProvider
51
64
*/
52
- public function testGetAttributes ($ eavEntityType , $ callNum , array $ expected )
65
+ public function testExecute ($ eavEntityType , $ callNum , array $ expected, $ isStatic = true )
53
66
{
54
- $ metadataMock = $ this ->getMockBuilder (EntityMetadataInterface::class)
67
+ $ entityData = ['linkField ' => 'theLinkField ' ];
68
+ $ this ->metadataMock ->method ('getEavEntityType ' )
69
+ ->willReturn ($ eavEntityType );
70
+ $ connectionMock = $ this ->getMockBuilder (\Magento \Framework \DB \Adapter \AdapterInterface::class)
55
71
->disableOriginalConstructor ()
56
72
->getMock ();
57
- $ this ->metadataPoolMock ->expects ($ this ->once ())
58
- ->method ('getMetadata ' )
59
- ->willReturn ($ metadataMock );
60
- $ metadataMock ->expects ($ this ->once ())
61
- ->method ('getEavEntityType ' )
62
- ->willReturn ($ eavEntityType );
73
+ $ selectMock = $ this ->getMockBuilder (\Magento \Framework \DB \Select::class)
74
+ ->disableOriginalConstructor ()
75
+ ->getMock ();
76
+ $ selectMock ->method ('from ' )
77
+ ->willReturnSelf ();
78
+ $ selectMock ->method ('where ' )
79
+ ->willReturnSelf ();
80
+ $ connectionMock ->method ('select ' )
81
+ ->willReturn ($ selectMock );
82
+ $ connectionMock ->method ('fetchAll ' )
83
+ ->willReturn (
84
+ [
85
+ [
86
+ 'attribute_id ' => 'attributeId ' ,
87
+ 'value ' => 'attributeValue ' ,
88
+ ]
89
+ ]
90
+ );
91
+ $ this ->metadataMock ->method ('getEntityConnection ' )
92
+ ->willReturn ($ connectionMock );
93
+ $ this ->metadataMock ->method ('getLinkField ' )
94
+ ->willReturn ('linkField ' );
95
+
63
96
$ attributeMock = $ this ->getMockBuilder (AbstractAttribute::class)
64
97
->disableOriginalConstructor ()
65
98
->getMock ();
99
+ $ attributeMock ->method ('isStatic ' )
100
+ ->willReturn ($ isStatic );
101
+ $ backendMock = $ this ->getMockBuilder (\Magento \Eav \Model \Entity \Attribute \Backend \AbstractBackend::class)
102
+ ->disableOriginalConstructor ()
103
+ ->getMock ();
104
+ $ backendMock ->method ('getTable ' )
105
+ ->willReturn ('backendTable ' );
106
+ $ attributeMock ->method ('getBackend ' )
107
+ ->willReturn ($ backendMock );
108
+ $ attributeMock ->method ('getAttributeId ' )
109
+ ->willReturn ('attributeId ' );
110
+ $ attributeMock ->method ('getAttributeCode ' )
111
+ ->willReturn ('attributeCode ' );
66
112
$ this ->configMock ->expects ($ this ->exactly ($ callNum ))
67
113
->method ('getAttributes ' )
68
114
->willReturn ([$ attributeMock ]);
@@ -71,25 +117,30 @@ public function testGetAttributes($eavEntityType, $callNum, array $expected)
71
117
'getAttributes '
72
118
);
73
119
$ getAttributesMethod ->setAccessible (true );
74
- $ this ->assertEquals ($ expected , $ getAttributesMethod -> invoke ( $ this ->readHandler , 'entity_type ' ));
120
+ $ this ->assertEquals ($ expected , $ this ->readHandler -> execute ( 'entity_type ' , $ entityData ));
75
121
}
76
122
77
- public function getAttributesDataProvider ()
123
+ public function executeDataProvider ()
78
124
{
79
- $ attributeMock = $ this ->getMockBuilder (AbstractAttribute::class)
80
- ->disableOriginalConstructor ()
81
- ->getMock ();
82
-
83
125
return [
84
- [null , 0 , []],
85
- ['env-entity-type ' , 1 , [$ attributeMock ]]
126
+ 'null entity type ' => [null , 0 , ['linkField ' => 'theLinkField ' ]],
127
+ 'static attribute ' => ['env-entity-type ' , 1 , ['linkField ' => 'theLinkField ' ]],
128
+ 'non-static attribute ' => [
129
+ 'env-entity-type ' ,
130
+ 1 ,
131
+ [
132
+ 'linkField ' => 'theLinkField ' ,
133
+ 'attributeCode ' => 'attributeValue '
134
+ ],
135
+ false
136
+ ],
86
137
];
87
138
}
88
139
89
140
/**
90
141
* @expectedException \Exception
91
142
*/
92
- public function testGetAttributesWithException ()
143
+ public function testExecuteWithException ()
93
144
{
94
145
$ this ->metadataPoolMock ->expects ($ this ->once ())
95
146
->method ('getMetadata ' )
0 commit comments