From 5a670857c9a93c4964a6ce07ded939693f64d5c6 Mon Sep 17 00:00:00 2001 From: Evgeny Ruban Date: Wed, 17 Sep 2025 18:09:01 +0400 Subject: [PATCH] fix-force-option - --- src/Module/Common/FileSystem/FS.php | 4 ++-- tests/Acceptance/DLoadTest.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Module/Common/FileSystem/FS.php b/src/Module/Common/FileSystem/FS.php index c7febab..a7af8f0 100644 --- a/src/Module/Common/FileSystem/FS.php +++ b/src/Module/Common/FileSystem/FS.php @@ -102,11 +102,11 @@ public static function removeDir(Path $path, bool $recursive = true): bool * * @param Path $from Source file path * @param Path $to Destination file path - * @param bool $overwrite Whether to overwrite the destination file if it exists (default: false) + * @param bool $overwrite Whether to overwrite the destination file if it exists (default: true) * * @throws \RuntimeException If the move operation fails */ - public static function moveFile(Path $from, Path $to, bool $overwrite = false): bool + public static function moveFile(Path $from, Path $to, bool $overwrite = true): bool { if ($from->absolute() === $to->absolute()) { return true; // No need to move if paths are the same diff --git a/tests/Acceptance/DLoadTest.php b/tests/Acceptance/DLoadTest.php index 1a42855..363a642 100644 --- a/tests/Acceptance/DLoadTest.php +++ b/tests/Acceptance/DLoadTest.php @@ -60,6 +60,34 @@ public function testDownloadsTrapPharSuccessfully(): void } } + public function testDownloadsTrapPharSuccessfullyWithForceOption(): void + { + // Arrange + $downloadConfig = new DownloadConfig(); + $downloadConfig->software = 'trap'; + $downloadConfig->version = '1.13.16'; + $downloadConfig->type = Type::Phar; + $downloadConfig->extractPath = (string) $this->destinationDir; + + // Act + $this->dload->addTask($downloadConfig); + $this->dload->run(); + $this->dload->addTask($downloadConfig, true); + $this->dload->run(); + + // Assert - Check that trap.phar was downloaded + $expectedPharPath = (string) $this->destinationDir->join('trap.phar'); + self::assertFileExists($expectedPharPath, 'Trap PHAR should be downloaded to destination directory'); + + // Verify the file is not empty + self::assertGreaterThan(1024, \filesize($expectedPharPath), 'Downloaded PHAR should have substantial size'); + + // Verify file permissions (should be executable) + if (PHP_OS_FAMILY !== 'Windows') { + self::assertTrue(\is_executable($expectedPharPath), 'PHAR file should be executable'); + } + } + public function testDownloadsTrapBinary(): void { // Arrange