Skip to content

Commit 9d713ae

Browse files
committed
test: added missing tests for class Filesystem
1 parent 54dc3dd commit 9d713ae

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

phpmyfaq/src/phpMyFAQ/Filesystem.php

+7-9
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ public function createDirectory(string $pathname, int $mode = 0777, bool $recurs
110110

111111
/**
112112
* Moves given directory.
113-
*
114-
*
115113
*/
116114
public function moveDirectory(string $sourcePath, string $destinationPath): bool
117115
{
@@ -148,21 +146,21 @@ public function deleteDirectory(string $pathname): bool
148146
}
149147

150148
/**
151-
* Copies the source file to the destination.
149+
* Copies the source file to the destination file.
152150
*
153151
* @throws Exception
154152
*/
155-
public function copy(string $source, string $dest): bool
153+
public function copy(string $sourceFileName, string $destinationFileName): bool
156154
{
157-
if (!is_readable($source)) {
158-
throw new Exception($source . ' is not readable.');
155+
if (!is_readable($sourceFileName)) {
156+
throw new Exception($sourceFileName . ' is not readable.');
159157
}
160158

161-
if (!is_writable(dirname($dest))) {
162-
throw new Exception($dest . ' is not writeable.');
159+
if (!is_writable(dirname($destinationFileName))) {
160+
throw new Exception($destinationFileName . ' is not writeable.');
163161
}
164162

165-
if (!copy($source, $dest)) {
163+
if (copy($sourceFileName, $destinationFileName) === false) {
166164
$error = error_get_last();
167165
throw new Exception($error['message']);
168166
}

tests/phpMyFAQ/FilesystemTest.php

+32-9
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,54 @@ public function testCreateDirectoryDuplicateDirectory(): void
4444

4545
public function testCopy(): void
4646
{
47-
$this->markTestSkipped();
47+
$this->filesystem->createDirectory(PMF_CONTENT_DIR . '/copy-test');
48+
$actual = $this->filesystem->copy(
49+
PMF_TEST_DIR . '/path/foo.bar',
50+
PMF_CONTENT_DIR . '/copy-test/foo.bar'
51+
);
52+
$this->assertTrue($actual);
53+
54+
$actual = $this->filesystem->deleteDirectory(PMF_CONTENT_DIR . '/copy-test');
55+
$this->assertTrue($actual);
4856
}
4957

5058
public function testSetPath(): void
5159
{
52-
$this->markTestSkipped();
60+
$this->filesystem->setPath(PMF_CONTENT_DIR);
61+
$this->assertEquals(PMF_CONTENT_DIR, $this->filesystem->getPath());
5362
}
5463

5564
public function testMoveDirectory(): void
5665
{
57-
$this->markTestSkipped();
66+
$this->filesystem->createDirectory(PMF_CONTENT_DIR . '/move-directory-test');
67+
$actual = $this->filesystem->moveDirectory(
68+
PMF_CONTENT_DIR . '/move-directory-test',
69+
PMF_CONTENT_DIR . '/move-directory-test-moved'
70+
);
71+
$this->assertTrue($actual);
72+
$actual = $this->filesystem->deleteDirectory(PMF_CONTENT_DIR . '/move-directory-test-moved');
73+
$this->assertTrue($actual);
5874
}
5975

6076
public function testRecursiveCopy(): void
6177
{
62-
$this->markTestSkipped();
63-
}
78+
$testDirectory = PMF_CONTENT_DIR . '/recursive-copy-test';
6479

65-
public function testGetPath(): void
66-
{
67-
$this->markTestSkipped();
80+
$actual = $this->filesystem->recursiveCopy(PMF_TEST_DIR . '/fixtures', $testDirectory);
81+
$this->assertTrue($actual);
82+
83+
$actual = is_file(PMF_CONTENT_DIR . '/recursive-copy-test/fixtures/foo.bar');
84+
$this->assertTrue($actual);
85+
86+
$actual = $this->filesystem->deleteDirectory($testDirectory);
87+
$this->assertTrue($actual);
6888
}
6989

7090
public function testGetRootPath(): void
7191
{
72-
$this->markTestSkipped();
92+
$this->assertEquals(
93+
PMF_TEST_DIR,
94+
$this->filesystem->getRootPath()
95+
);
7396
}
7497
}

0 commit comments

Comments
 (0)