From 9d713aeb988880570bde3196c6096fd00cb9f449 Mon Sep 17 00:00:00 2001 From: Thorsten Rinne Date: Sun, 16 Jul 2023 14:22:25 +0200 Subject: [PATCH] test: added missing tests for class Filesystem --- phpmyfaq/src/phpMyFAQ/Filesystem.php | 16 +++++------ tests/phpMyFAQ/FilesystemTest.php | 41 ++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/phpmyfaq/src/phpMyFAQ/Filesystem.php b/phpmyfaq/src/phpMyFAQ/Filesystem.php index e0ff2eb71e..e9d2660684 100644 --- a/phpmyfaq/src/phpMyFAQ/Filesystem.php +++ b/phpmyfaq/src/phpMyFAQ/Filesystem.php @@ -110,8 +110,6 @@ public function createDirectory(string $pathname, int $mode = 0777, bool $recurs /** * Moves given directory. - * - * */ public function moveDirectory(string $sourcePath, string $destinationPath): bool { @@ -148,21 +146,21 @@ public function deleteDirectory(string $pathname): bool } /** - * Copies the source file to the destination. + * Copies the source file to the destination file. * * @throws Exception */ - public function copy(string $source, string $dest): bool + public function copy(string $sourceFileName, string $destinationFileName): bool { - if (!is_readable($source)) { - throw new Exception($source . ' is not readable.'); + if (!is_readable($sourceFileName)) { + throw new Exception($sourceFileName . ' is not readable.'); } - if (!is_writable(dirname($dest))) { - throw new Exception($dest . ' is not writeable.'); + if (!is_writable(dirname($destinationFileName))) { + throw new Exception($destinationFileName . ' is not writeable.'); } - if (!copy($source, $dest)) { + if (copy($sourceFileName, $destinationFileName) === false) { $error = error_get_last(); throw new Exception($error['message']); } diff --git a/tests/phpMyFAQ/FilesystemTest.php b/tests/phpMyFAQ/FilesystemTest.php index cd9baf0cbc..659f211b66 100644 --- a/tests/phpMyFAQ/FilesystemTest.php +++ b/tests/phpMyFAQ/FilesystemTest.php @@ -44,31 +44,54 @@ public function testCreateDirectoryDuplicateDirectory(): void public function testCopy(): void { - $this->markTestSkipped(); + $this->filesystem->createDirectory(PMF_CONTENT_DIR . '/copy-test'); + $actual = $this->filesystem->copy( + PMF_TEST_DIR . '/path/foo.bar', + PMF_CONTENT_DIR . '/copy-test/foo.bar' + ); + $this->assertTrue($actual); + + $actual = $this->filesystem->deleteDirectory(PMF_CONTENT_DIR . '/copy-test'); + $this->assertTrue($actual); } public function testSetPath(): void { - $this->markTestSkipped(); + $this->filesystem->setPath(PMF_CONTENT_DIR); + $this->assertEquals(PMF_CONTENT_DIR, $this->filesystem->getPath()); } public function testMoveDirectory(): void { - $this->markTestSkipped(); + $this->filesystem->createDirectory(PMF_CONTENT_DIR . '/move-directory-test'); + $actual = $this->filesystem->moveDirectory( + PMF_CONTENT_DIR . '/move-directory-test', + PMF_CONTENT_DIR . '/move-directory-test-moved' + ); + $this->assertTrue($actual); + $actual = $this->filesystem->deleteDirectory(PMF_CONTENT_DIR . '/move-directory-test-moved'); + $this->assertTrue($actual); } public function testRecursiveCopy(): void { - $this->markTestSkipped(); - } + $testDirectory = PMF_CONTENT_DIR . '/recursive-copy-test'; - public function testGetPath(): void - { - $this->markTestSkipped(); + $actual = $this->filesystem->recursiveCopy(PMF_TEST_DIR . '/fixtures', $testDirectory); + $this->assertTrue($actual); + + $actual = is_file(PMF_CONTENT_DIR . '/recursive-copy-test/fixtures/foo.bar'); + $this->assertTrue($actual); + + $actual = $this->filesystem->deleteDirectory($testDirectory); + $this->assertTrue($actual); } public function testGetRootPath(): void { - $this->markTestSkipped(); + $this->assertEquals( + PMF_TEST_DIR, + $this->filesystem->getRootPath() + ); } }