mirror of https://github.com/rectorphp/rector.git
59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Rector\Tests\FileFormatter\Formatter\YamlFileFormatter;
|
|
|
|
use Iterator;
|
|
use Rector\Core\ValueObject\Application\File;
|
|
use Rector\FileFormatter\Formatter\YamlFileFormatter;
|
|
use Rector\FileFormatter\ValueObject\Indent;
|
|
use Rector\FileFormatter\ValueObjectFactory\EditorConfigConfigurationBuilder;
|
|
use Rector\Testing\PHPUnit\AbstractTestCase;
|
|
use Symplify\EasyTesting\DataProvider\StaticFixtureFinder;
|
|
use Symplify\EasyTesting\StaticFixtureSplitter;
|
|
use Symplify\SmartFileSystem\SmartFileInfo;
|
|
|
|
final class YamlFileFormatterTest extends AbstractTestCase
|
|
{
|
|
private YamlFileFormatter $yamlFileFormatter;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->boot();
|
|
$this->yamlFileFormatter = $this->getService(YamlFileFormatter::class);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideData()
|
|
*/
|
|
public function test(SmartFileInfo $fileInfo): void
|
|
{
|
|
$this->doTestFileInfo($fileInfo);
|
|
}
|
|
|
|
/**
|
|
* @return Iterator<array<int, SmartFileInfo>>
|
|
*/
|
|
public function provideData(): Iterator
|
|
{
|
|
return StaticFixtureFinder::yieldDirectory(__DIR__ . '/Fixture', '*.yaml');
|
|
}
|
|
|
|
private function doTestFileInfo(SmartFileInfo $smartFileInfo): void
|
|
{
|
|
$inputFileInfoAndExpected = StaticFixtureSplitter::splitFileInfoToLocalInputAndExpected($smartFileInfo);
|
|
|
|
$inputFileInfo = $inputFileInfoAndExpected->getInputFileInfo();
|
|
$file = new File($inputFileInfo, $inputFileInfo->getContents());
|
|
|
|
$editorConfigConfigurationBuilder = new EditorConfigConfigurationBuilder();
|
|
$editorConfigConfigurationBuilder->withIndent(Indent::createSpaceWithSize(4));
|
|
$editorConfigConfigurationBuilder->withInsertFinalNewline(false);
|
|
|
|
$this->yamlFileFormatter->format($file, $editorConfigConfigurationBuilder->build());
|
|
|
|
$this->assertSame($inputFileInfoAndExpected->getExpected(), $file->getFileContent());
|
|
}
|
|
}
|