|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Symfony\Bundle\MakerBundle\Tests\Util; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | +use Symfony\Bundle\MakerBundle\Util\TemplateLinter; |
| 7 | +use Symfony\Component\Filesystem\Filesystem; |
| 8 | + |
| 9 | +/** |
| 10 | + * @author Jesse Rushlow <[email protected]> |
| 11 | + */ |
| 12 | +class TemplateLinterTest extends TestCase |
| 13 | +{ |
| 14 | + public function testLinterFixesPhpFile(): void |
| 15 | + { |
| 16 | + $linter = new TemplateLinter(); |
| 17 | + |
| 18 | + $fixture = $this->copySourceToTemp('TemplateLinterController.php'); |
| 19 | + |
| 20 | + $linter->lintPhpTemplate($fixture); |
| 21 | + |
| 22 | + self::assertFileEquals(__DIR__.'/fixtures/template_linter/ExpectedTemplateLinterController.php', $fixture); |
| 23 | + } |
| 24 | + |
| 25 | + /** @dataProvider pathProvider */ |
| 26 | + public function testLinterThrowsExceptionIfBinaryOrArgumentDoNotExist(string $binaryPath, string $configPath): void |
| 27 | + { |
| 28 | + $this->expectExceptionMessage('Either the config or binary for PHP_CS_FIXER does not exist.'); |
| 29 | + |
| 30 | + new TemplateLinter($binaryPath, $configPath); |
| 31 | + } |
| 32 | + |
| 33 | + public function pathProvider(): \Generator |
| 34 | + { |
| 35 | + yield 'Binary Path Wrong' => ['/bad/path', dirname(__DIR__, 2).'/src/Resources/config/php-cs-fixer.config.php']; |
| 36 | + yield 'Config Path Wrong' => [dirname(__DIR__, 2).'/src/Bin/php-cs-fixer-v3.13.0.phar', '/bad/path']; |
| 37 | + yield 'Both Paths Wrong' => ['/bad/path', '/bad/path']; |
| 38 | + } |
| 39 | + |
| 40 | + private function copySourceToTemp(string $sourceFileName): string |
| 41 | + { |
| 42 | + $file = new Filesystem(); |
| 43 | + $sourcePath = __DIR__.'/fixtures/source/'; |
| 44 | + $tmpLocation = dirname(__DIR__).'/tmp/cache/linter-test/'; |
| 45 | + |
| 46 | + $file->copy($sourcePath.$sourceFileName, $tmpLocation.$sourceFileName); |
| 47 | + |
| 48 | + return $tmpLocation.$sourceFileName; |
| 49 | + } |
| 50 | +} |
0 commit comments