Skip to content
This repository was archived by the owner on Jun 18, 2025. It is now read-only.

Commit c7059f3

Browse files
authored
fix: default file permissions (#37)
1 parent 1007301 commit c7059f3

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/LocalFilesystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ private function getDirectoryPermissionsFromParams(array $params): int
410410
*/
411411
private function getFilePermissionsFromParams(array $params): int
412412
{
413-
return $params['filePermissions'] ?? $this->defaultDirectoryPermissions;
413+
return $params['filePermissions'] ?? $this->defaultFilePermissions;
414414
}
415415

416416
private function getLastErrorAsException(): LocalFilesystemException

tests/LocalFilesystemTest.php

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class LocalFilesystemTest extends TestCase
4242

4343
protected function setUp(): void
4444
{
45-
$this->filesystem = new LocalFilesystem(__DIR__ . '/tmp/' . (string) microtime(true));
45+
$this->filesystem = new LocalFilesystem($this->getLocation());
4646

4747
// Fix test on differrent platforms
4848
umask(0);
@@ -116,13 +116,45 @@ public function testGetNotExistingFilePermissions(): void
116116
$this->filesystem->getPermissions(self::NOT_EXISTING_FILE_NAME);
117117
}
118118

119-
public function testWritingToFileAndDeletingFile(): void
119+
public function testWritingToFile(): void
120120
{
121121
$this->filesystem->writeToFile(self::FILE_NAME, self::FILE_CONTENT);
122122
$this->assertTrue($this->filesystem->fileExists(self::FILE_NAME));
123123

124+
$filePath = self::DIRECTORY_NAME . '/' . self::FILE_NAME;
125+
$this->filesystem->writeToFile($filePath, self::FILE_CONTENT);
126+
$this->assertTrue($this->filesystem->fileExists($filePath));
127+
}
128+
129+
public function testWritingToFileWheDirectoryExists(): void
130+
{
124131
$this->filesystem->createDirectory(self::DIRECTORY_NAME);
125-
$this->filesystem->writeToFile(self::DIRECTORY_NAME . '/' . self::FILE_NAME, self::FILE_CONTENT);
132+
133+
$filePath = self::DIRECTORY_NAME . '/' . self::FILE_NAME;
134+
$this->filesystem->writeToFile($filePath, self::FILE_CONTENT);
135+
$this->assertTrue($this->filesystem->fileExists($filePath));
136+
}
137+
138+
public function testWritingToFileByFilesystemWithCustomPermissions(): void
139+
{
140+
$filesystem = new LocalFilesystem($this->getLocation(), [
141+
'defaultPermissions' => [
142+
'directory' => 0777,
143+
'file' => 0666,
144+
],
145+
]);
146+
147+
$filePath = self::DIRECTORY_NAME . '/' . self::FILE_NAME;
148+
$filesystem->writeToFile($filePath, self::FILE_CONTENT);
149+
$this->assertTrue($filesystem->fileExists($filePath));
150+
151+
$this->assertEquals('0777', LocalFilesystemHelper::filepermsToOctatValue(
152+
$filesystem->getPermissions(self::DIRECTORY_NAME)
153+
));
154+
155+
$this->assertEquals('0666', LocalFilesystemHelper::filepermsToOctatValue(
156+
$filesystem->getPermissions(self::DIRECTORY_NAME . '/' . self::FILE_NAME)
157+
));
126158
}
127159

128160
public function testWritingToFileWithPermissions(): void
@@ -326,4 +358,9 @@ public function testDeletingNotExistingDirectoryByFullPath(): void
326358
$this->expectException(LocalFilesystemException::class);
327359
$method->invokeArgs($this->filesystem, [self::NOT_EXISTING_DIRECTORY_NAME]);
328360
}
361+
362+
private function getLocation(): string
363+
{
364+
return __DIR__ . '/tmp/' . (string) microtime(true);
365+
}
329366
}

0 commit comments

Comments
 (0)