1

这是我的 phpstan.neon

  parameters:
  checkMissingIterableValueType: false
  checkGenericClassInNonGenericObjectType: false
  symfony:
        container_xml_path: '%rootDir%/../../../var/cache/dev/srcApp_KernelDevDebugContainer.xml'
  bootstrap: '%rootDir%/../../../vendor/autoload.php'

这是我的 gitlab-ci 片段

commit:
  stage: analysis
  variables:
    APP_ENV: dev
  cache:
    untracked: true
    paths:
     - Source/var/cache/dev/
  before_script:
    - cd Source
    - cp .env.example .env
    - composer install --no-interaction --optimize-autoloader --classmap-authoritative
  script:
    - composer commit
  only:
    - merge_requests

我收到以下错误:

In XmlServiceMapFactory.php line 29:

   [PHPStan\Symfony\XmlContainerNotExistsException]                             
   Container /builds/Mehlichmeyer/heracles-mvp-symfony/Source/vendor/phpstan/p  
   hpstan/../../../var/cache/dev/srcApp_KernelDevDebugContainer.xml does not e  
   xist                  

问题是我的 gitlab-ci 容器没有 srcApp_KernelDevDebugContainer.xml,因为它在我的 .gitignore 中(/var/ 是)。任何解决方法的想法?

4

2 回答 2

2

要拥有此文件,您必须在激活调试的情况下为开发环境生成缓存。我想它可以在“before_script”部分完成:

before_script:
    - cd Source
    - cp .env.example .env
    - composer install --no-interaction --optimize-autoloader --classmap-authoritative
    - php bin/console cache:warmup --env=dev

您的.env文件必须具有调试标志:

###> symfony/framework-bundle ###
APP_ENV=dev
APP_DEBUG=1
APP_SECRET=APP_SECRET
###< symfony/framework-bundle ###

我不知道 gitlab-ci,但我用 github-actions 做到了这一点,而且效果很好。

于 2020-03-06T06:51:28.383 回答
0

好的,所以我终于找到了问题。我将 Symfony 从 4.x 更新到 5.x,我不得不调整我的 phpstan.neon

container_xml_path: '%rootDir%/../../../var/cache/dev/App_KernelDevDebugContainer.xml'

在本地,这从未引发错误,因为我没有运行 bin/console cache:clear,所以旧的 container_xml_path 工作正常。

于 2020-03-06T11:18:43.473 回答