@@ -105,4 +105,45 @@ public function reset_clears_all_state(): void
105105 $ this ->expectException (RuntimeException::class);
106106 OpenApiSpecLoader::getBasePath ();
107107 }
108+
109+ #[Test]
110+ public function clear_cache_keeps_config (): void
111+ {
112+ $ fixturesPath = __DIR__ . '/../fixtures/specs ' ;
113+ OpenApiSpecLoader::configure ($ fixturesPath , ['/api ' ]);
114+
115+ // Load to populate cache
116+ OpenApiSpecLoader::load ('petstore-3.0 ' );
117+
118+ OpenApiSpecLoader::clearCache ();
119+
120+ // Config is preserved
121+ $ this ->assertSame ($ fixturesPath , OpenApiSpecLoader::getBasePath ());
122+ $ this ->assertSame (['/api ' ], OpenApiSpecLoader::getStripPrefixes ());
123+
124+ // Cache is cleared — next load reads from disk again
125+ $ spec = OpenApiSpecLoader::load ('petstore-3.0 ' );
126+ $ this ->assertSame ('3.0.3 ' , $ spec ['openapi ' ]);
127+ }
128+
129+ #[Test]
130+ public function evict_removes_single_spec_from_cache (): void
131+ {
132+ $ fixturesPath = __DIR__ . '/../fixtures/specs ' ;
133+ OpenApiSpecLoader::configure ($ fixturesPath );
134+
135+ // Load two specs
136+ $ first30 = OpenApiSpecLoader::load ('petstore-3.0 ' );
137+ $ first31 = OpenApiSpecLoader::load ('petstore-3.1 ' );
138+
139+ // Evict only 3.0
140+ OpenApiSpecLoader::evict ('petstore-3.0 ' );
141+
142+ // 3.1 still cached (same reference)
143+ $ this ->assertSame ($ first31 , OpenApiSpecLoader::load ('petstore-3.1 ' ));
144+
145+ // 3.0 reloaded from disk (equal but fresh instance)
146+ $ reloaded30 = OpenApiSpecLoader::load ('petstore-3.0 ' );
147+ $ this ->assertSame ($ first30 , $ reloaded30 );
148+ }
108149}
0 commit comments