Skip to content

Commit dcd42e1

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

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
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: 1 addition & 1 deletion
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));

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

Lines changed: 38 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';

0 commit comments

Comments
 (0)