Skip to content

Commit ee288c9

Browse files
committed
assert the linter is working
1 parent 383ef3e commit ee288c9

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

tests/Util/TemplateLinterTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
namespace Symfony\Bundle\MakerBundle\Tests\Util\fixtures\source;
3+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
4+
use Symfony\Component\HttpFoundation\Response;
5+
/**
6+
* @author Jesse Rushlow <[email protected]>
7+
*/
8+
class TemplateLinterController extends AbstractController
9+
{
10+
public function index(): Response{return $this->render('some/template.html.twig');}
11+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\MakerBundle\Tests\Util\fixtures\source;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6+
use Symfony\Component\HttpFoundation\Response;
7+
8+
/**
9+
* @author Jesse Rushlow <[email protected]>
10+
*/
11+
class TemplateLinterController extends AbstractController
12+
{
13+
public function index(): Response
14+
{
15+
return $this->render('some/template.html.twig');
16+
}
17+
}

0 commit comments

Comments
 (0)