Skip to content

Commit

Permalink
dir permissions fixed, now are octal
Browse files Browse the repository at this point in the history
  • Loading branch information
goffyara committed Apr 9, 2021
1 parent 0505f41 commit 6793b49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/CodeGenerator/Filesystem/FilePutContentsFileWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace OnMoon\OpenApiServerBundle\CodeGenerator\Filesystem;

use function intval;
use function is_dir;
use function Safe\file_put_contents;
use function Safe\mkdir;
Expand All @@ -14,9 +15,9 @@ final class FilePutContentsFileWriter implements FileWriter
{
private int $dirPemissions;

public function __construct(int $dirPemissions)
public function __construct(string $dirPemissions)
{
$this->dirPemissions = $dirPemissions;
$this->dirPemissions = intval($dirPemissions, 8);
}

public function write(string $path, string $filename, string $contents): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;

use function decoct;
use function fileperms;
use function Safe\file_get_contents;
use function Safe\rmdir;
use function Safe\unlink;
Expand All @@ -26,14 +28,18 @@ public function testWriteCreatesFile(): void
$fullPath = $path . DIRECTORY_SEPARATOR . $filename;
$fileContent = 'Some Random Content';

$fileWriter = new FilePutContentsFileWriter(0755);
$fileWriter = new FilePutContentsFileWriter('0755');

Assert::assertFileDoesNotExist($fullPath);
Assert::assertDirectoryDoesNotExist($path);

$fileWriter->write($path, $filename, $fileContent);

Assert::assertDirectoryExists($path);

/** @var int $permissions */
$permissions = fileperms($path);
Assert::assertSame('40755', decoct($permissions));
Assert::assertFileExists($fullPath);
Assert::assertEquals($fileContent, file_get_contents($fullPath));

Expand Down

0 comments on commit 6793b49

Please sign in to comment.