Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dir permissions fixed, now are octal #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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