Skip to content

Commit b6aa002

Browse files
committed
test linter works in project
1 parent ee288c9 commit b6aa002

File tree

4 files changed

+87
-3
lines changed

4 files changed

+87
-3
lines changed

tests/Maker/TemplateLinterTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony MakerBundle package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\MakerBundle\Tests\Maker;
13+
14+
use Symfony\Bundle\MakerBundle\Maker\MakeVoter;
15+
use Symfony\Bundle\MakerBundle\Test\MakerTestCase;
16+
use Symfony\Bundle\MakerBundle\Test\MakerTestRunner;
17+
18+
/**
19+
* This test is not testing a maker directly. But the files generated by a maker.
20+
*
21+
* @author Jesse Rushlow <[email protected]>
22+
*/
23+
class TemplateLinterTest extends MakerTestCase
24+
{
25+
protected function getMakerClass(): string
26+
{
27+
// We can use any maker here - MakeVoter is the simplest for now.
28+
return MakeVoter::class;
29+
}
30+
31+
public function getTestDetails(): \Generator
32+
{
33+
yield 'lints_templates_with_custom_php_cs_fixer_and_config' => [$this->createMakerTest()
34+
->addExtraDependencies('friendsofphp/php-cs-fixer')
35+
->run(function (MakerTestRunner $runner) {
36+
$runner->copy('template-linter/php-cs-fixer.test.php', 'php-cs-fixer.test.php');
37+
38+
$runner->replaceInFile(
39+
'.env',
40+
'###< symfony/framework-bundle ###',
41+
<<< 'EOT'
42+
MAKER_PHP_CS_FIXER_CONFIG_PATH=php-cs-fixer.test.php
43+
MAKER_PHP_CS_FIXER_BINARY_PATH=bin/php-cs-fixer
44+
EOT
45+
);
46+
47+
// Voter class name
48+
$runner->runMaker(['FooBar']);
49+
50+
$generatedTemplate = file_get_contents($runner->getPath('src/Security/Voter/FooBarVoter.php'));
51+
52+
self::assertStringContainsString('Linted by custom php-cs-config', $generatedTemplate);
53+
}),
54+
];
55+
}
56+
}

tests/Util/TemplateLinterTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony MakerBundle package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Bundle\MakerBundle\Tests\Util;
413

514
use PHPUnit\Framework\TestCase;
@@ -32,16 +41,16 @@ public function testLinterThrowsExceptionIfBinaryOrArgumentDoNotExist(string $bi
3241

3342
public function pathProvider(): \Generator
3443
{
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'];
44+
yield 'Binary Path Wrong' => ['/bad/path', \dirname(__DIR__, 2).'/src/Resources/config/php-cs-fixer.config.php'];
45+
yield 'Config Path Wrong' => [\dirname(__DIR__, 2).'/src/Bin/php-cs-fixer-v3.13.0.phar', '/bad/path'];
3746
yield 'Both Paths Wrong' => ['/bad/path', '/bad/path'];
3847
}
3948

4049
private function copySourceToTemp(string $sourceFileName): string
4150
{
4251
$file = new Filesystem();
4352
$sourcePath = __DIR__.'/fixtures/source/';
44-
$tmpLocation = dirname(__DIR__).'/tmp/cache/linter-test/';
53+
$tmpLocation = \dirname(__DIR__).'/tmp/cache/linter-test/';
4554

4655
$file->copy($sourcePath.$sourceFileName, $tmpLocation.$sourceFileName);
4756

tests/fixtures/template-linter/.env

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony MakerBundle package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
return (new PhpCsFixer\Config())
13+
->setRules([
14+
'header_comment' => [
15+
'header' => 'Linted by custom php-cs-config',
16+
],
17+
])
18+
->setRiskyAllowed(true)
19+
;

0 commit comments

Comments
 (0)