Skip to content

Commit 45c871c

Browse files
committed
use file manager to get the root project path
1 parent 431cd14 commit 45c871c

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

src/Resources/config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
</service>
4242

4343
<service id="maker.template_linter" class="Symfony\Bundle\MakerBundle\Util\TemplateLinter">
44+
<argument type="service" id="maker.file_manager" />
4445
<argument>%env(default::string:MAKER_PHP_CS_FIXER_BINARY_PATH)%</argument>
4546
<argument>%env(default::string:MAKER_PHP_CS_FIXER_CONFIG_PATH)%</argument>
4647
</service>

src/Util/TemplateLinter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\MakerBundle\Util;
1313

1414
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
15+
use Symfony\Bundle\MakerBundle\FileManager;
1516
use Symfony\Component\Console\Output\OutputInterface;
1617
use Symfony\Component\Process\ExecutableFinder;
1718
use Symfony\Component\Process\Process;
@@ -30,6 +31,7 @@ final class TemplateLinter
3031
private bool $needsPhpCmdPrefix = true;
3132

3233
public function __construct(
34+
private FileManager $fileManager,
3335
private ?string $phpCsFixerBinaryPath = null,
3436
private ?string $phpCsFixerConfigPath = null,
3537
) {
@@ -132,7 +134,7 @@ private function setBinary(): void
132134
private function setConfig(): void
133135
{
134136
// No config provided, but there is a dist config file in the project dir
135-
$defaultConfigPath = \sprintf('.php-cs-fixer.dist.php', \dirname(__DIR__, 2));
137+
$defaultConfigPath = \sprintf('%s/.php-cs-fixer.dist.php', $this->fileManager->getRootDirectory());
136138
if (null === $this->phpCsFixerConfigPath && file_exists($defaultConfigPath)) {
137139
$this->phpCsFixerConfigPath = $defaultConfigPath;
138140

tests/Maker/TemplateLinterTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ protected function getMakerClass(): string
3333
public function getTestDetails(): \Generator
3434
{
3535
yield 'lints_templates_with_custom_php_cs_fixer_and_config' => [$this->createMakerTest()
36-
->addExtraDependencies('php-cs-fixer/shim')
3736
->run(function (MakerTestRunner $runner) {
3837
$runner->copy('template-linter/php-cs-fixer.test.php', 'php-cs-fixer.test.php');
3938

@@ -53,13 +52,12 @@ public function getTestDetails(): \Generator
5352

5453
self::assertStringContainsString('Linted by custom php-cs-config', $generatedTemplate);
5554

56-
$expectedOutput = 'System PHP-CS-Fixer (bin/php-cs-fixer) & System PHP-CS-Fixer Configuration (php-cs-fixer.test.php)';
55+
$expectedOutput = 'System PHP-CS-Fixer (bin/php-cs-fixer) & System PHP-CS-Fixer Configuration';
5756
self::assertStringContainsString($expectedOutput, $output);
5857
}),
5958
];
6059

6160
yield 'lints_templates_with_flex_generated_config_file' => [$this->createMakerTest()
62-
->addExtraDependencies('php-cs-fixer/shim')
6361
->run(function (MakerTestRunner $runner) {
6462
$runner->replaceInFile(
6563
'.php-cs-fixer.dist.php',
@@ -79,13 +77,14 @@ public function getTestDetails(): \Generator
7977

8078
self::assertStringContainsString('Linted with stock php-cs-config', $generatedTemplate);
8179

82-
$expectedOutput = 'Bundled PHP-CS-Fixer & System PHP-CS-Fixer Configuration (.php-cs-fixer.dist.php)';
80+
$expectedOutput = 'Bundled PHP-CS-Fixer & System PHP-CS-Fixer Configuration';
8381
self::assertStringContainsString($expectedOutput, $output);
8482
}),
8583
];
8684

8785
yield 'lints_templates_with_bundled_php_cs_fixer' => [$this->createMakerTest()
8886
->run(function (MakerTestRunner $runner) {
87+
$runner->deleteFile('.php-cs-fixer.dist.php');
8988
// Voter class name
9089
$output = $runner->runMaker(['FooBar']);
9190

tests/Util/TemplateLinterTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Composer\InstalledVersions;
1515
use PHPUnit\Framework\TestCase;
16+
use Symfony\Bundle\MakerBundle\FileManager;
1617
use Symfony\Bundle\MakerBundle\Util\TemplateLinter;
1718
use Symfony\Component\Process\Process;
1819

@@ -29,14 +30,14 @@ public function testExceptionBinaryPathDoesntExist(): void
2930
{
3031
$this->expectExceptionMessage('The MAKER_PHP_CS_FIXER_BINARY_PATH provided: /some/bad/path does not exist.');
3132

32-
new TemplateLinter(phpCsFixerBinaryPath: '/some/bad/path');
33+
new TemplateLinter($this->createMock(FileManager::class), phpCsFixerBinaryPath: '/some/bad/path');
3334
}
3435

3536
public function testExceptionThrownIfConfigPathDoesntExist(): void
3637
{
3738
$this->expectExceptionMessage('The MAKER_PHP_CS_FIXER_CONFIG_PATH provided: /bad/config/path does not exist.');
3839

39-
new TemplateLinter(phpCsFixerConfigPath: '/bad/config/path');
40+
new TemplateLinter($this->createMock(FileManager::class), phpCsFixerConfigPath: '/bad/config/path');
4041
}
4142

4243
public function testPhpCsFixerVersion(): void

0 commit comments

Comments
 (0)