Rector: Impossibile to use Rector in test environment (due to PHPStan use)

Created on 3 Jul 2020  路  6Comments  路  Source: rectorphp/rector

Bug Report

| Subject | Details |
| :------------- | :---------------------------------------------------------------|
| Rector version | e.g. v0.7.41 |

Error reported

PHP Warning: file_get_contents(/path/to/app/vendor/phpstan/phpstan/../../../var/cache/dev/srcApp_KernelDevDebugContainer.xml): failed to open stream: No such file or directory in /path/to/app/vendor/phpstan/phpstan-symfony/src/Symfony/XmlServiceMapFactory.php on line 27

Description of the issue

Trying to run Rector in CI we get the above error, caused by PHPStan that cannot find the container compiled in dev: in fact we are in test env, and so the dev container doesn't exist.

Steps to reproduce the issue

In a Symfony app:

  1. Manually remove the folder var/cache/dev
  2. Recreate the cache for the test env running bin/console cache:clear --env test
  3. Create the file rector.yaml (see below for the contents of the file)
  4. Create the file rector.test.yaml (see below for the content of the file)
  5. Run Rector loading the test config file: vendor/bin/rector process src --dry-run --config=rector.test.yaml

rector.yaml

parameters:
    php_version_features: '7.2'
    sets:
      - 'php52'
      - 'php53'
      - 'php54'
      - 'php56'
      - 'php70'
      - 'php71'
      - 'php72'
      - 'code-quality'
      - 'coding-style'
      - 'doctrine'
      - 'phpstan'
      - 'framework-extra-bundle-30'
      - 'framework-extra-bundle-40'
      - 'framework-extra-bundle-50'
      - 'symfony-code-quality'
      - 'symfony-constructor-injection'
      - 'symfony42'
    autoload_paths:
      - 'config/bootstrap.php'
    exclude_paths:
        - '*/Migrations/*'

rector.test.yaml

imports:
  - { resource: 'rector.yaml'}

parameters:
  symfony_container_xml_path: 'var/cache/test/srcApp_KernelTestDebugContainer.xml'

Expected behavior

Rector is able to pass to PHPStan the correct config file, depending on the environment.

This issue was already addressed (but not solved) in

feature

All 6 comments

How would you fix it?

@TomasVotruba I have no idea: I don't know how the file is loaded nor how it is involved in Rector.

In PHPStan I pass it directly to the command line this way:

./vendor/bin/phpstan analyse src -c phpstan.test.neon --level max

So I think Rector should accept the same:

  • Via command line config (--phpstan-config phpstan.test.neon)
  • Via the Recotr's config file rector.test.yaml with a key like phpstan_config_file_path.

This way it is possible to pass to PHPStan the correct config file.

--phpstan-config

Sound good. Coul you add such feature here?

I don't know how the file is loaded nor how it is involved in Rector.

If you search for phpstan.neon, it's the first file:
https://github.com/rectorphp/rector/search?q=phpstan.neon&unscoped_q=phpstan.neon

@TomasVotruba , I will try to find time to work on this, but I cannot guarantee nothing.

The quarantine was very hard for me and now I can dedicate less than one hour a day (when I can) to development.

Closing for lack of feedback for last 4 months.

Was this page helpful?
0 / 5 - 0 ratings