Skip to content

Commit 4f109b3

Browse files
committed
test: cover filesystem functions
1 parent b610ea2 commit 4f109b3

File tree

2 files changed

+461
-3
lines changed

2 files changed

+461
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@ function get_directory(string $node, int $levels = 1): string
3333
/**
3434
* Copies a file from `$source` to `$destination`.
3535
*/
36-
function copy(string $source, string $destination, bool $overwrite = false): void
36+
function copy_file(string $source, string $destination, bool $overwrite = false): void
3737
{
3838
$destination_exists = namespace\is_file($destination);
3939

4040
if (! $overwrite && $destination_exists) {
4141
return;
4242
}
4343

44+
if (namespace\is_directory($source)) {
45+
throw Exceptions\NotFileException::for($source);
46+
}
47+
4448
if (! namespace\is_file($source)) {
4549
throw Exceptions\NotFoundException::forFile($source);
4650
}
@@ -49,9 +53,13 @@ function copy(string $source, string $destination, bool $overwrite = false): voi
4953
throw Exceptions\NotReadableException::forFile($source);
5054
}
5155

52-
if (! php_copy($source, $destination)) {
56+
namespace\create_directory_for_file($destination);
57+
58+
[$result, $errorMessage] = box(static fn (): bool => php_copy($source, $destination));
59+
60+
if ($result === false) {
5361
throw new Exceptions\RuntimeException(
54-
sprintf('Failed to copy source file "%s" to destination "%s".', $source, $destination),
62+
sprintf('Failed to copy source file "%s" to destination "%s": %s', $source, $destination, $errorMessage),
5563
);
5664
}
5765
}

0 commit comments

Comments
 (0)