Skip to content

Commit 5ddac5f

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-52105' into MAGETWO-52835
2 parents 1121148 + b8417be commit 5ddac5f

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,15 @@ public function getHydrator($entityType)
106106
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
107107
return $objectManager->get(HydratorPool::class)->getHydrator($entityType);
108108
}
109+
110+
/**
111+
* Check if entity type configuration was set to metadata
112+
*
113+
* @param string $entityType
114+
* @return bool
115+
*/
116+
public function hasConfiguration($entityType)
117+
{
118+
return isset($this->metadata[$entityType]);
119+
}
109120
}

lib/internal/Magento/Framework/EntityManager/Test/Unit/TypeResolverTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ class TypeResolverTest extends \PHPUnit_Framework_TestCase
1717
*/
1818
private $resolver;
1919

20+
/**
21+
* @var \Magento\Framework\EntityManager\MetadataPool|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
private $metadataPoolMock;
24+
2025
public function setUp()
2126
{
2227
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
23-
$this->resolver = new \Magento\Framework\EntityManager\TypeResolver();
28+
$this->metadataPoolMock = $this->getMock('\Magento\Framework\EntityManager\MetadataPool', [], [], '', false);
29+
$this->resolver = new \Magento\Framework\EntityManager\TypeResolver($this->metadataPoolMock);
2430
}
2531

2632
/**
@@ -31,6 +37,13 @@ public function setUp()
3137
public function testResolve($dataObject, $interfaceName)
3238
{
3339
$customerDataObject = $this->objectManager->getObject($dataObject);
40+
$this->metadataPoolMock->expects($this->any())
41+
->method('hasConfiguration')
42+
->willReturnMap(
43+
[
44+
[$interfaceName, true]
45+
]
46+
);
3447
$this->assertEquals($interfaceName, $this->resolver->resolve($customerDataObject));
3548
}
3649

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
*/
1111
class TypeResolver
1212
{
13+
/**
14+
* @var MetadataPool
15+
*/
16+
private $metadataPool;
17+
1318
/**
1419
* @var array
1520
*/
@@ -18,6 +23,15 @@ class TypeResolver
1823
\Magento\SalesRule\Model\Rule\Interceptor::class => \Magento\SalesRule\Api\Data\RuleInterface::class
1924
];
2025

26+
/**
27+
* TypeResolver constructor.
28+
* @param MetadataPool $metadataPool
29+
*/
30+
public function __construct(MetadataPool $metadataPool)
31+
{
32+
$this->metadataPool = $metadataPool;
33+
}
34+
2135
/**
2236
* @param object $type
2337
* @return string
@@ -45,6 +59,12 @@ public function resolve($type)
4559
throw new \Exception('Unable to determine data interface for ' . $className);
4660
}
4761

48-
return reset($dataInterfaces);
62+
foreach ($dataInterfaces as $dataInterface) {
63+
if ($this->metadataPool->hasConfiguration($dataInterface)) {
64+
$this->typeMapping[$className] = $dataInterface;
65+
}
66+
}
67+
68+
return $this->typeMapping[$className];
4969
}
5070
}

0 commit comments

Comments
 (0)