8000 [Cache][PoC] Upgrade TagAwareAdapter · symfony/symfony@0e8d14d · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 0e8d14d

Browse files
committed
[Cache][PoC] Upgrade TagAwareAdapter
1 parent bd3b056 commit 0e8d14d

File tree

4 files changed

+48
-464
lines changed

4 files changed

+48
-464
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,20 @@ private function doTestCachePools($options, $adapterClass)
9393
$item = $pool2->getItem($key);
9494
$this->assertTrue($item->isHit());
9595

96-
$prefix = "\0".TagAwareAdapter::class."\0";
9796
$pool4 = $container->get('cache.pool4');
9897
$this->assertInstanceof(TagAwareAdapter::class, $pool4);
99-
$pool4 = (array) $pool4;
100-
$this->assertSame($pool4[$prefix.'pool'], $pool4[$prefix.'tags'] ?? $pool4['tags']);
98+
$pool4 = $this->getPrivateProperties($pool4, ['pool', 'tagPool']);
99+
$this->assertSame($pool4['pool'], $pool4['tagPool']);
101100

102101
$pool5 = $container->get('cache.pool5');
103102
$this->assertInstanceof(TagAwareAdapter::class, $pool5);
104-
$pool5 = (array) $pool5;
105-
$this->assertSame($pool2, $pool5[$prefix.'tags'] ?? $pool5['tags']);
103+
$pool5 = $this->getPrivateProperties($pool5, ['pool', 'tagPool']);
104+
$this->assertSame($pool2, $pool5['tagPool']);
106105

107106
$pool6 = $container->get('cache.pool6');
108107
$this->assertInstanceof(TagAwareAdapter::class, $pool6);
109-
$pool6 = (array) $pool6;
110-
$this->assertSame($pool4[$prefix.'pool'], $pool6[$prefix.'tags'] ?? $pool6['tags']);
108+
$pool6 = $this->getPrivateProperties($pool6, ['pool', 'tagPool']);
109+
$this->assertSame($pool4['pool'], $pool6['tagPool']);
111110

112111
$pool7 = $container->get('cache.pool7');
113112
$this->assertNotInstanceof(TagAwareAdapter::class, $pool7);
@@ -126,4 +125,25 @@ private function skipIfRedisUnavailable()
126125
self::markTestSkipped($e->getMessage());
127126
}
128127
}
128+
129+
private function getPrivateProperties($object, array $propertyNames)
130+
{
131+
$properties = [];
132+
$reflectionClass = new \ReflectionClass($object);
133+
134+
do {
135+
foreach ($reflectionClass->getProperties(\ReflectionProperty::IS_PRIVATE) as $property) {
136+
$name = $property->getName();
137+
if (\in_array($name, $propertyNames) && !isset($properties[$name])) {
138+
$property->setAccessible(true);
139+
$properties[$name] = $property->getValue($object);
140+
if (\count($properties) === \count($propertyNames)) {
141+
break 2;
142+
}
143+
}
144+
}
145+
} while ($reflectionClass = $reflectionClass->getParentClass());
146+
147+
return $properties;
148+
}
129149
}

0 commit comments

Comments
 (0)
0