@@ -93,21 +93,20 @@ private function doTestCachePools($options, $adapterClass)
93
93
$ item = $ pool2 ->getItem ($ key );
94
94
$ this ->assertTrue ($ item ->isHit ());
95
95
96
- $ prefix = "\0" .TagAwareAdapter::class."\0" ;
97
96
$ pool4 = $ container ->get ('cache.pool4 ' );
98
97
$ 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 ' ]);
101
100
102
101
$ pool5 = $ container ->get ('cache.pool5 ' );
103
102
$ 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 ' ]);
106
105
107
106
$ pool6 = $ container ->get ('cache.pool6 ' );
108
107
$ 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 ' ]);
111
110
112
111
$ pool7 = $ container ->get ('cache.pool7 ' );
113
112
$ this ->assertNotInstanceof (TagAwareAdapter::class, $ pool7 );
@@ -126,4 +125,25 @@ private function skipIfRedisUnavailable()
126
125
self ::markTestSkipped ($ e ->getMessage ());
127
126
}
128
127
}
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
+ }
129
149
}
0 commit comments