Skip to content

Commit 84a8141

Browse files
ACPT-1186
Collector: Restore compatibility to ResetAfterRequestTest since it doesn't yet use the custom ObjectManager for the state tests
1 parent d2e11ef commit 84a8141

File tree

1 file changed

+18
-7
lines changed
  • dev/tests/integration/testsuite/Magento/GraphQl/App/State

1 file changed

+18
-7
lines changed

dev/tests/integration/testsuite/Magento/GraphQl/App/State/Collector.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ class Collector
1818
private readonly array $skipListFromConstructed;
1919
private readonly array $skipListBetweenRequests;
2020

21-
/** @var ObjectManager $objectManager Note: Using ObjectManagerInterface for DI to get correct instance */
22-
2321
public function __construct(
2422
private readonly ObjectManagerInterface $objectManager,
2523
SkipListAndFilterList $skipListAndFilterList
@@ -76,15 +74,26 @@ function ($element) use (
7674
}
7775

7876
/**
79-
* Gets shared objects from ObjectManager using reflection and clones properties that are objects
77+
* Gets shared objects from ObjectManager using reflection and copies properties that are objects
8078
*
8179
* @param ShouldResetState $shouldResetState
8280
* @return CollectedObject[]
8381
*/
8482
public function getSharedObjects(ShouldResetState $shouldResetState): array
8583
{
84+
if ($this->objectManager instanceof ObjectManager) {
85+
$sharedInstances = $this->objectManager->getSharedInstances();
86+
} else {
87+
$obj = new \ReflectionObject($this->objectManager);
88+
if (!$obj->hasProperty('_sharedInstances')) {
89+
throw new \Exception('Cannot get shared objects from ' . get_class($this->objectManager));
90+
}
91+
$property = $obj->getProperty('_sharedInstances');
92+
$property->setAccessible(true);
93+
$sharedInstances = $property->getValue($this->objectManager);
94+
}
8695
$sharedObjects = [];
87-
foreach ($this->objectManager->getSharedInstances() as $serviceName => $object) {
96+
foreach ($sharedInstances as $serviceName => $object) {
8897
if (array_key_exists($serviceName, $sharedObjects)) {
8998
continue;
9099
}
@@ -154,9 +163,11 @@ public function getPropertiesFromObject(
154163
if (array_key_exists($className, $skipList)) {
155164
return CollectedObject::getSkippedObject();
156165
}
157-
$serviceName = array_search($object, $this->objectManager->getSharedInstances());
158-
if ($serviceName && array_key_exists($serviceName, $skipList)) {
159-
return CollectedObject::getSkippedObject();
166+
if ($this->objectManager instanceof ObjectManager) {
167+
$serviceName = array_search($object, $this->objectManager->getSharedInstances());
168+
if ($serviceName && array_key_exists($serviceName, $skipList)) {
169+
return CollectedObject::getSkippedObject();
170+
}
160171
}
161172
$objReflection = new \ReflectionObject($object);
162173
$properties = [];

0 commit comments

Comments
 (0)