Skip to content

Commit

Permalink
test: added missing tests for class Filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Jul 16, 2023
1 parent 54dc3dd commit 9d713ae
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
16 changes: 7 additions & 9 deletions phpmyfaq/src/phpMyFAQ/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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']);
}
Expand Down
41 changes: 32 additions & 9 deletions tests/phpMyFAQ/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}

0 comments on commit 9d713ae

Please sign in to comment.