rector/tests/PhpParser/Printer/FormatPerservingPrinterTest.php
Thomas Gerbet 68bda32d06 Preserve file permissions when updating a file
The change of permissions is not explicitely requested by the user
and is not shown in the dry-run. It makes Rector harder to use when
the sources of a project has some executable scripts.
2019-05-06 21:47:51 +02:00

43 lines
1.2 KiB
PHP

<?php declare(strict_types=1);
namespace Rector\Tests\PhpParser\Printer;
use Nette\Utils\FileSystem;
use Rector\HttpKernel\RectorKernel;
use Rector\PhpParser\Printer\FormatPerservingPrinter;
use Symplify\PackageBuilder\FileSystem\SmartFileInfo;
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
final class FormatPerservingPrinterTest extends AbstractKernelTestCase
{
/**
* @var FormatPerservingPrinter
*/
private $formatPerservingPrinter;
protected function setUp(): void
{
$this->bootKernel(RectorKernel::class);
$this->formatPerservingPrinter = self::$container->get(FormatPerservingPrinter::class);
}
protected function tearDown(): void
{
FileSystem::delete(__DIR__ . '/Fixture');
}
public function testFileModeIsPreserved(): void
{
mkdir(__DIR__ . '/Fixture');
touch(__DIR__ . '/Fixture/file.php');
$expectedFilemod = 0755;
chmod(__DIR__ . '/Fixture/file.php', $expectedFilemod);
$fileInfo = new SmartFileInfo(__DIR__ . '/Fixture/file.php');
$this->formatPerservingPrinter->printToFile($fileInfo, [], [], []);
$this->assertSame($expectedFilemod, fileperms(__DIR__ . '/Fixture/file.php') & 0777);
}
}