99use Patchlevel \Hydrator \Guesser \Guesser ;
1010use Patchlevel \Hydrator \HydratorBuilder ;
1111use Patchlevel \Hydrator \Metadata \AttributeMetadataFactory ;
12+ use Patchlevel \Hydrator \Metadata \EnrichingMetadataFactory ;
1213use Patchlevel \Hydrator \Metadata \MetadataEnricher ;
14+ use Patchlevel \Hydrator \Metadata \Psr16MetadataFactory ;
15+ use Patchlevel \Hydrator \Metadata \Psr6MetadataFactory ;
1316use Patchlevel \Hydrator \MetadataHydrator ;
1417use Patchlevel \Hydrator \Middleware \Middleware ;
1518use PHPUnit \Framework \Attributes \CoversClass ;
1619use PHPUnit \Framework \TestCase ;
20+ use Psr \Cache \CacheItemPoolInterface ;
21+ use Psr \SimpleCache \CacheInterface ;
1722use ReflectionProperty ;
1823
1924#[CoversClass(HydratorBuilder::class)]
@@ -54,8 +59,13 @@ public function testAddMetadataEnricherWithPriority(): void
5459
5560 $ hydrator = $ builder ->build ();
5661
57- $ reflection = new ReflectionProperty (MetadataHydrator::class, 'metadataEnrichers ' );
58- $ enrichers = $ reflection ->getValue ($ hydrator );
62+ $ reflection = new ReflectionProperty (MetadataHydrator::class, 'metadataFactory ' );
63+ $ enrichingMetadataFactory = $ reflection ->getValue ($ hydrator );
64+
65+ self ::assertInstanceOf (EnrichingMetadataFactory::class, $ enrichingMetadataFactory );
66+
67+ $ reflection = new ReflectionProperty (EnrichingMetadataFactory::class, 'enrichers ' );
68+ $ enrichers = $ reflection ->getValue ($ enrichingMetadataFactory );
5969
6070 self ::assertSame ([$ enricher2 , $ enricher1 ], $ enrichers );
6171 }
@@ -72,7 +82,12 @@ public function testAddGuesserWithPriority(): void
7282 $ hydrator = $ builder ->build ();
7383
7484 $ reflection = new ReflectionProperty (MetadataHydrator::class, 'metadataFactory ' );
75- $ metadataFactory = $ reflection ->getValue ($ hydrator );
85+ $ enrichingMetadataFactory = $ reflection ->getValue ($ hydrator );
86+
87+ self ::assertInstanceOf (EnrichingMetadataFactory::class, $ enrichingMetadataFactory );
88+
89+ $ reflection = new ReflectionProperty (EnrichingMetadataFactory::class, 'factory ' );
90+ $ metadataFactory = $ reflection ->getValue ($ enrichingMetadataFactory );
7691
7792 self ::assertInstanceOf (AttributeMetadataFactory::class, $ metadataFactory );
7893
@@ -109,4 +124,34 @@ public function testUseExtension(): void
109124
110125 $ builder ->useExtension ($ extension );
111126 }
127+
128+ public function testCachePsr6 (): void
129+ {
130+ $ cache = $ this ->createMock (CacheItemPoolInterface::class);
131+
132+ $ builder = new HydratorBuilder ();
133+ $ builder ->setCache ($ cache );
134+
135+ $ hydrator = $ builder ->build ();
136+
137+ $ reflection = new ReflectionProperty (MetadataHydrator::class, 'metadataFactory ' );
138+ $ factory = $ reflection ->getValue ($ hydrator );
139+
140+ self ::assertInstanceOf (Psr6MetadataFactory::class, $ factory );
141+ }
142+
143+ public function testCachePsr16 (): void
144+ {
145+ $ cache = $ this ->createMock (CacheInterface::class);
146+
147+ $ builder = new HydratorBuilder ();
148+ $ builder ->setCache ($ cache );
149+
150+ $ hydrator = $ builder ->build ();
151+
152+ $ reflection = new ReflectionProperty (MetadataHydrator::class, 'metadataFactory ' );
153+ $ factory = $ reflection ->getValue ($ hydrator );
154+
155+ self ::assertInstanceOf (Psr16MetadataFactory::class, $ factory );
156+ }
112157}
0 commit comments