Skip to content

Commit

Permalink
refactor: fix todo test with new functionality and cleanup some warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Ben James <[email protected]>
  • Loading branch information
benjam-es committed Jan 18, 2025
1 parent dcfe9bf commit b3bf9e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Plugins/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}

Expand Down
18 changes: 12 additions & 6 deletions tests/Unit/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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,
Expand Down

0 comments on commit b3bf9e7

Please sign in to comment.