Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DistFileLoader doesn't import another file #1133

Open
mischabraam opened this issue May 16, 2024 · 0 comments
Open

DistFileLoader doesn't import another file #1133

mischabraam opened this issue May 16, 2024 · 0 comments

Comments

@mischabraam
Copy link

mischabraam commented May 16, 2024

Q A
Version 2.5.0
Bug? yes
New feature? no
Question? no
Documentation? dunno

We've made a base module which actually just contains a bunch of distributed static analysis files. For tools like phpcs, phpstan and such. And, obviously, also for grumphp. The distribution files in this module are installed through composer and end up in the vendor directory. They can be used as import in the 'root' configuration files or directly.
The bug is happening when we have a grumphp.yml file in the root of the project, which imports a grumphp.yml.dist file from a vendor location. The bug specifically occurs when the imported file is a .dist file. When this imported file not a dist, but a .yml the bug does not occur. It doesn't really matter where this .dist file is located.
The bug concerns the src/Configuration/Loader/DistFileLoader.php which doesn't (correctly) resolve the path to the dist file. In comparison; the Symfony YamlFileLoader (which is used if you import a .yml file) does resolve the path to the yml file correctly.

Configuration which doesn't work (aka the bug)

# ./grumphp.yml
imports:
  - { resource: 'vendor/some/base-module/grumphp.yml.dist' }

or

# ./grumphp.yml
imports:
  - { resource: 'grumphp.yml.dist' }

Configuration which works

# ./grumphp.yml
imports:
  - { resource: 'vendor/some/base-module/grumphp.yml' }

or

# ./grumphp.yml
imports:
  - { resource: '/AbsolutePath/WhichIsNotPreferredIn/CI/CD/project/vendor/some/base-module/grumphp.yml.dist' }

The error output concerning the bug is as follows.

Fatal error: Uncaught Symfony\Component\Config\Exception\FileLocatorFileNotFoundException: The file "vendor/some/base-module/grumphp.yml.dist" does not exist (in: "/Users/mischabraam/Development/Sites/myproject/vendor/phpro/grumphp/resources/config"). in /Users/mischabraam/Development/Sites/myproject/vendor/symfony/config/FileLocator.php:73
Stack trace:
#0 /Users/mischabraam/Development/Sites/myproject/vendor/symfony/dependency-injection/Loader/YamlFileLoader.php(123): Symfony\Component\Config\FileLocator->locate('vendor/some/base...')
#1 /Users/mischabraam/Development/Sites/myproject/vendor/phpro/grumphp/src/Configuration/Loader/DistFileLoader.php(27): Symfony\Component\DependencyInjection\Loader\YamlFileLoader->load('vendor/some/base...', NULL)
#2 /Users/mischabraam/Development/Sites/myproject/vendor/symfony/config/Loader/FileLoader.php(146): GrumPHP\Configuration\Loader\DistFileLoader->load('vendor/some/base...', NULL)
#3 /Users/mischabraam/Development/Sites/myproject/vendor/symfony/config/Loader/FileLoader.php(98): Symfony\Component\Config\Loader\FileLoader->doImport('vendor/some/base...', NULL, false, '/Users/mischabr...')
#4 /Users/mischabraam/Development/Sites/myproject/vendor/symfony/dependency-injection/Loader/FileLoader.php(70): Symfony\Component\Config\Loader\FileLoader->import('vendor/some/base...', NULL, false, '/Users/mischabr...')
#5 /Users/mischabraam/Development/Sites/myproject/vendor/symfony/dependency-injection/Loader/YamlFileLoader.php(219): Symfony\Component\DependencyInjection\Loader\FileLoader->import('vendor/some/base...', NULL, false, '/Users/mischabr...')
#6 /Users/mischabraam/Development/Sites/myproject/vendor/symfony/dependency-injection/Loader/YamlFileLoader.php(158): Symfony\Component\DependencyInjection\Loader\YamlFileLoader->parseImports(Array, '/Users/mischabr...')
#7 /Users/mischabraam/Development/Sites/myproject/vendor/symfony/dependency-injection/Loader/YamlFileLoader.php(135): Symfony\Component\DependencyInjection\Loader\YamlFileLoader->loadContent(Array, '/Users/mischabr...')
#8 /Users/mischabraam/Development/Sites/myproject/vendor/symfony/config/Loader/DelegatingLoader.php(37): Symfony\Component\DependencyInjection\Loader\YamlFileLoader->load('/Users/mischabr...', NULL)
#9 /Users/mischabraam/Development/Sites/myproject/vendor/phpro/grumphp/src/Configuration/ContainerBuilder.php(47): Symfony\Component\Config\Loader\DelegatingLoader->load('/Users/mischabr...')
#10 /Users/mischabraam/Development/Sites/myproject/vendor/phpro/grumphp/src/Configuration/ContainerFactory.php(28): GrumPHP\Configuration\ContainerBuilder::buildFromConfiguration('/Users/mischabr...')
#11 /Users/mischabraam/Development/Sites/myproject/vendor/phpro/grumphp/bin/grumphp(46): GrumPHP\Configuration\ContainerFactory::build(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /Users/mischabraam/Development/Sites/myproject/vendor/phpro/grumphp/bin/grumphp(51): {closure}()
#13 /Users/mischabraam/Development/Sites/myproject/vendor/bin/grumphp(119): include('/Users/mischabr...')
#14 {main}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant