Skip to content

Commit d11e469

Browse files
committed
test: improve coverage
1 parent dbbadc6 commit d11e469

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

src/Tempest/Support/src/Filesystem/Exceptions/NotFoundException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
final class NotFoundException extends Exception implements FilesystemException
88
{
9-
public static function forNode(string $node): static
9+
public static function forPath(string $path): static
1010
{
11-
return new self(sprintf('Node "%s" is not found.', $node));
11+
return new self(sprintf('Path "%s" is not found.', $path));
1212
}
1313

1414
public static function forFile(string $file): static

src/Tempest/Support/src/Filesystem/functions.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ function delete_file(string $file): void
241241
function get_permissions(string $path): int
242242
{
243243
if (! namespace\exists($path)) {
244-
throw Exceptions\NotFoundException::forNode($path);
244+
throw Exceptions\NotFoundException::forPath($path);
245245
}
246246

247247
[$result, $message] = box(static fn (): int|false => fileperms($path));
@@ -271,7 +271,9 @@ function ensure_directory_empty(string $directory): void
271271
return;
272272
}
273273

274-
$permissions = namespace\get_permissions($directory);
274+
$permissions = PHP_OS_FAMILY === 'Windows'
275+
? namespace\get_permissions($directory)
276+
: 0o777;
275277

276278
namespace\delete_directory($directory, recursive: true);
277279
namespace\create_directory($directory, $permissions);

src/Tempest/Support/tests/Filesystem/FunctionsTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Tempest\Support\Filesystem\Exceptions\NotFileException;
99
use Tempest\Support\Filesystem\Exceptions\NotFoundException;
1010
use Tempest\Support\Filesystem\Exceptions\NotReadableException;
11+
use Tempest\Support\Filesystem\Exceptions\NotSymbolicLinkException;
1112
use Tempest\Support\Filesystem\Exceptions\RuntimeException;
1213

1314
final class FunctionsTest extends TestCase
@@ -197,6 +198,17 @@ public function test_get_permissions(): void
197198
$this->assertEquals(0o644, $permissions & 0o777);
198199
}
199200

201+
public function test_get_permissions_not_found(): void
202+
{
203+
if (PHP_OS_FAMILY === 'Windows') {
204+
$this->markTestSkipped('Irrelevant on Windows.');
205+
}
206+
207+
$this->expectException(NotFoundException::class);
208+
209+
Filesystem\get_permissions($this->fixtures . '/file.txt');
210+
}
211+
200212
public function test_ensure_directory_empty(): void
201213
{
202214
$dir = $this->fixtures . '/tmp';
@@ -310,6 +322,17 @@ public function test_list_directory(): void
310322
}
311323
}
312324

325+
public function test_list_directory_on_non_directory(): void
326+
{
327+
$this->expectException(NotDirectoryException::class);
328+
329+
$file = $this->fixtures . '/file.txt';
330+
331+
file_put_contents($file, '');
332+
333+
Filesystem\list_directory($file);
334+
}
335+
313336
public function test_read_symbolic_link(): void
314337
{
315338
$file = $this->fixtures . '/file.txt';
@@ -323,6 +346,21 @@ public function test_read_symbolic_link(): void
323346
$this->assertEquals(realpath($file), $target);
324347
}
325348

349+
public function test_read_symbolic_link_on_non_symlink(): void
350+
{
351+
if (PHP_OS_FAMILY === 'Windows') {
352+
$this->markTestSkipped('Irrelevant on Windows.');
353+
}
354+
355+
$this->expectException(NotSymbolicLinkException::class);
356+
357+
$file = $this->fixtures . '/file.txt';
358+
359+
file_put_contents($file, '');
360+
361+
Filesystem\read_symbolic_link($file);
362+
}
363+
326364
public function test_get_directory(): void
327365
{
328366
$file = $this->fixtures . '/file.txt';
@@ -410,6 +448,10 @@ public function test_write_file(): void
410448

411449
public function test_write_non_writable_file(): void
412450
{
451+
if (PHP_OS_FAMILY === 'Windows') {
452+
$this->markTestSkipped('Irrelevant on Windows.');
453+
}
454+
413455
$this->expectException(RuntimeException::class);
414456

415457
$file = $this->fixtures . '/file.txt';

0 commit comments

Comments
 (0)