@@ -166,6 +166,45 @@ public function testCreatesDirectoryOnConstruction(): void
166166 $ this ->removeDir ($ dir );
167167 }
168168
169+ public function testConstructorThrowsWhenDirectoryCannotBeCreated (): void
170+ {
171+ // Create a file where the directory should be — mkdir will fail
172+ $ blockingFile = sys_get_temp_dir () . '/kc_block_ ' . uniqid ();
173+ file_put_contents ($ blockingFile , 'blocking ' );
174+
175+ // Trying to create a directory INSIDE the blocking file triggers mkdir failure
176+ $ impossibleDir = $ blockingFile . '/subdir ' ;
177+
178+ $ this ->expectException (DiscoveryException::class);
179+
180+ try {
181+ new FileCacheStrategy ($ impossibleDir );
182+ } finally {
183+ unlink ($ blockingFile );
184+ }
185+ }
186+
187+ public function testClearReturnsSilentlyWhenDirectoryUnreadable (): void
188+ {
189+ // Populate some cache files first
190+ $ this ->cache ->set ('x ' , new DiscoveryResult ());
191+
192+ // Make the cache directory unreadable so glob() returns false
193+ chmod ($ this ->cacheDir , 0o000 );
194+
195+ if (is_readable ($ this ->cacheDir )) {
196+ chmod ($ this ->cacheDir , 0o755 );
197+ $ this ->markTestSkipped ('Cannot make directory unreadable (running as root). ' );
198+ }
199+
200+ // clear() must not throw — just return early (L94)
201+ $ this ->cache ->clear ();
202+ $ this ->assertTrue (true ); // reached here without exception
203+
204+ // Restore so tearDown can clean up
205+ chmod ($ this ->cacheDir , 0o755 );
206+ }
207+
169208 private function removeDir (string $ dir ): void
170209 {
171210 if (! is_dir ($ dir )) {
0 commit comments