From b3bf9e7e1735206efee2b8b0529ce720c5054a2a Mon Sep 17 00:00:00 2001 From: Ben James Date: Sat, 18 Jan 2025 16:06:53 +0000 Subject: [PATCH] refactor: fix todo test with new functionality and cleanup some warnings Signed-off-by: Ben James --- src/Plugins/Cache.php | 2 +- tests/Unit/ConfigTest.php | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Plugins/Cache.php b/src/Plugins/Cache.php index 593865e..b192eeb 100644 --- a/src/Plugins/Cache.php +++ b/src/Plugins/Cache.php @@ -85,7 +85,7 @@ public function has(string $key): bool */ public function getCacheFile(string $key): string { - if (! is_dir($this->cacheDirectory) && ! mkdir($this->cacheDirectory, 0755, true)) { + if (! is_writable(dirname($this->cacheDirectory)) || (! is_dir($this->cacheDirectory) && ! mkdir($this->cacheDirectory, 0755, true))) { throw new RuntimeException("Could not create cache directory: {$this->cacheDirectory}"); } diff --git a/tests/Unit/ConfigTest.php b/tests/Unit/ConfigTest.php index d9d8749..a215576 100644 --- a/tests/Unit/ConfigTest.php +++ b/tests/Unit/ConfigTest.php @@ -31,9 +31,13 @@ }); it('should be able to create a peck.json config file', function (): void { - $configFilePath = __DIR__.'/../../peck.json'; - $backup = $configFilePath.'.backup'; - rename($configFilePath, $backup); + if (file_exists($filePath = dirname(__DIR__).'/peck-new.json')) { + unlink($filePath); + } + Config::flush(); + Config::resolveConfigFilePathUsing( + fn (): string => $filePath, + ); $created = Config::init(); $config = Config::instance(); @@ -42,8 +46,8 @@ ->and($config->whitelistedWords)->toBe(['php']) ->and($config->whitelistedPaths)->toBe([]); - rename($backup, $configFilePath); -})->skip('rewrite this test a little bit differently without modifying the root level peck.json file'); + unlink($filePath); +}); it('should not recreate a file that already exists', function (): void { $created = Config::init(); @@ -57,7 +61,9 @@ }); it('can set ignore words', function (): void { - unlink($filePath = dirname(__DIR__).'/peck-testing.json'); + if (file_exists($filePath = dirname(__DIR__).'/peck-testing.json')) { + unlink($filePath); + } Config::flush(); Config::resolveConfigFilePathUsing( fn (): string => $filePath,