【问题标题】:Phpstan with gitlab-ci cant find srcApp_KernelDevDebugContainer.xml because its in the gitignore?带有 gitlab-ci 的 Phpstan 找不到 srcApp_KernelDevDebugContainer.xml,因为它在 gitignore 中?
【发布时间】:2020-03-05 22:00:20
【问题描述】:

这是我的 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 sn-p

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/ 是)。任何解决方法的想法?

【问题讨论】:

  • 如果该容器文件不存在,为什么不通过bin/console cache:clear构建它?

标签: symfony gitlab gitlab-ci gitlab-ci-runner phpstan


【解决方案1】:

要获得此文件,您必须在激活调试的情况下为开发环境生成缓存。我想这可以在“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 做了这个,效果很好。

【讨论】:

  • 不幸的是,这不起作用。我已经在作曲家提交步骤 ``"phpstan": [ "bin/console cache:warmup --env=dev", "vendor/bin/phpstan analyze src/ -c phpstan.neon -- level=7 -vvv --no-progress --memory-limit=1G" ], "csfixer": [ "vendor/bin/php-cs-fixer fix" ], "commit": [ "@phpstan", " @csfixer" ]
【解决方案2】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-06
    • 2022-01-15
    • 1970-01-01
    • 2020-02-01
    • 2018-12-14
    • 1970-01-01
    • 1970-01-01
    • 2022-10-12
    相关资源
    最近更新 更多