@@ -68,4 +68,44 @@ public function testCacheDoesNotExceedMaxSize(): void
6868
6969 $ this ->assertEquals (2 , $ result );
7070 }
71+
72+ public function testGetPromotesToMostRecentlyUsedSoItDoesNotEvictNext (): void
73+ {
74+ $ cache = new ReflectionClassCache (2 );
75+
76+ $ classA = DummyDependency::class;
77+ $ classB = DummyNoConstructor::class;
78+ $ classC = DummySimpleConstructor::class;
79+
80+ $ cache ->put (new ReflectionClass ($ classA ));
81+ $ cache ->put (new ReflectionClass ($ classB ));
82+
83+ $ this ->assertNotNull ($ cache ->get ($ classA ));
84+
85+ $ cache ->put (new ReflectionClass ($ classC ));
86+
87+ $ this ->assertTrue ($ cache ->has ($ classA ));
88+ $ this ->assertFalse ($ cache ->has ($ classB ));
89+ $ this ->assertTrue ($ cache ->has ($ classC ));
90+ }
91+
92+ public function testPutRefreshesRecencySoReinsertedEntryIsNotEvicted (): void
93+ {
94+ $ cache = new ReflectionClassCache (2 );
95+
96+ $ classA = DummyDependency::class;
97+ $ classB = DummyNoConstructor::class;
98+ $ classC = DummySimpleConstructor::class;
99+
100+ $ cache ->put (new ReflectionClass ($ classA ));
101+ $ cache ->put (new ReflectionClass ($ classB ));
102+
103+ $ cache ->put (new ReflectionClass ($ classA ));
104+
105+ $ cache ->put (new ReflectionClass ($ classC ));
106+
107+ $ this ->assertTrue ($ cache ->has ($ classA ));
108+ $ this ->assertFalse ($ cache ->has ($ classB ));
109+ $ this ->assertTrue ($ cache ->has ($ classC ));
110+ }
71111}
0 commit comments