无法打开所需的/symfony/phpunit-bridge/bootstrap. php

k7fdbhmy  于 2023-08-06  发布在  PHP
关注(0)|答案(3)|浏览(101)

我目前正在使用Symfony 4.2开发一个REST API,并使用Docker(php-fpm)进行部署。
当尝试在构建的容器中运行phpunit测试时(设置ci),它确实失败了,给出以下输出:

$ docker run api:latest bin/phpunit

PHP Warning:  require(/srv/api/bin/.phpunit/phpunit-6.5/vendor/composer/../symfony/phpunit-bridge/bootstrap.php): failed to open stream: No such file or directory in /srv/api/bin/.phpunit/phpunit-6.5/vendor/composer/autoload_real.php on line 66
PHP Stack trace:
PHP   1. {main}() /srv/api/bin/phpunit:0
PHP   2. require() /srv/api/bin/phpunit:19
PHP   3. include() /srv/api/vendor/symfony/phpunit-bridge/bin/simple-phpunit:244
PHP   4. require() /srv/api/bin/.phpunit/phpunit-6.5/phpunit:4
PHP   5. ComposerAutoloaderInitfa3eadee0e53d49c951bc803cfc74f21::getLoader() /srv/api/bin/.phpunit/phpunit-6.5/vendor/autoload.php:7
PHP   6. composerRequirefa3eadee0e53d49c951bc803cfc74f21() /srv/api/bin/.phpunit/phpunit-6.5/vendor/composer/autoload_real.php:56
PHP Fatal error:  require(): Failed opening required '/srv/api/bin/.phpunit/phpunit-6.5/vendor/composer/../symfony/phpunit-bridge/bootstrap.php' (include_path='.:/usr/local/lib/php') in /srv/api/bin/.phpunit/phpunit-6.5/vendor/composer/autoload_real.php on line 66
PHP Stack trace:
PHP   1. {main}() /srv/api/bin/phpunit:0
PHP   2. require() /srv/api/bin/phpunit:19
PHP   3. include() /srv/api/vendor/symfony/phpunit-bridge/bin/simple-phpunit:244
PHP   4. require() /srv/api/bin/.phpunit/phpunit-6.5/phpunit:4
PHP   5. ComposerAutoloaderInitfa3eadee0e53d49c951bc803cfc74f21::getLoader() /srv/api/bin/.phpunit/phpunit-6.5/vendor/autoload.php:7
PHP   6. composerRequirefa3eadee0e53d49c951bc803cfc74f21() /srv/api/bin/.phpunit/phpunit-6.5/vendor/composer/autoload_real.php:56

字符串
Composer会安装所有必需的包,包括dev-packages。这是composer的输出:

Package operations: 94 installs, 0 updates, 0 removals

    [...]

You are using the deprecated option "dev". Dev packages are installed by default now.
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file

Prefetching 10 packages � �
  - Downloading (100%)

Package operations: 10 installs, 0 updates, 0 removals
  - Installing doctrine/data-fixtures (v1.3.1): Loading from cache
  - Installing doctrine/doctrine-fixtures-bundle (3.1.0): Loading from cache
  - Installing symfony/process (v4.2.3): Loading from cache
  - Installing symfony/polyfill-php72 (v1.10.0): Loading from cache
  - Installing php-cs-fixer/diff (v1.3.0): Loading from cache
  - Installing composer/xdebug-handler (1.3.2): Loading from cache
  - Installing composer/semver (1.4.2): Loading from cache
  - Installing friendsofphp/php-cs-fixer (v2.14.2): Loading from cache
  - Installing fzaninotto/faker (v1.8.0): Loading from cache
  - Installing symfony/phpunit-bridge (v4.2.3): Loading from cache
Generating autoload files
ocramius/package-versions:  Generating version class...
ocramius/package-versions: ...done generating version class
Executing script cache:clear [OK]
Executing script assets:install public [OK]

Generated autoload files containing 50 classes


错误消息中指定的文件确实存在:

$ ls -al vendor/composer/../symfony/phpunit-bridge
total 88
drwxr-xr-x    6 root     root          4096 Feb 21 12:59 .
drwxr-xr-x    1 root     root          4096 Feb 21 12:59 ..
-rw-r--r--    1 root     root            34 Feb 21 12:59 .gitignore
-rw-r--r--    1 root     root          1296 Feb 21 12:59 CHANGELOG.md
-rw-r--r--    1 root     root          2687 Feb 21 12:59 ClockMock.php
-rw-r--r--    1 root     root           868 Feb 21 12:59 CoverageListener.php
-rw-r--r--    1 root     root         13954 Feb 21 12:59 DeprecationErrorHandler.php
-rw-r--r--    1 root     root          6013 Feb 21 12:59 DnsMock.php
-rw-r--r--    1 root     root          1065 Feb 21 12:59 LICENSE
drwxrwxrwx    2 root     root          4096 Feb 21 12:59 Legacy
-rw-r--r--    1 root     root           500 Feb 21 12:59 README.md
-rw-r--r--    1 root     root           896 Feb 21 12:59 SymfonyTestsListener.php
drwxrwxrwx    4 root     root          4096 Feb 21 12:59 Tests
drwxrwxrwx    2 root     root          4096 Feb 21 12:59 TextUI
drwxrwxrwx    2 root     root          4096 Feb 21 12:59 bin
-rw-r--r--    1 root     root          1330 Feb 21 12:59 bootstrap.php # <-----
-rw-r--r--    1 root     root          1400 Feb 21 12:59 composer.json
-rw-r--r--    1 root     root           914 Feb 21 12:59 phpunit.xml.dist
$ ls -al bin/.phpunit/phpunit-6.5/vendor/composer
total 268
drwxr-xr-x    2 root     root          4096 Feb 10 12:03 .
drwxr-xr-x   14 root     root          4096 Feb 10 12:03 ..
-rwxr-xr-x    1 root     root         13459 Feb 10 12:03 ClassLoader.php
-rwxr-xr-x    1 root     root          1070 Feb 10 12:03 LICENSE
-rwxr-xr-x    1 root     root         83087 Feb 10 12:03 autoload_classmap.php
-rwxr-xr-x    1 root     root           440 Feb 10 12:03 autoload_files.php
-rwxr-xr-x    1 root     root           214 Feb 10 12:03 autoload_namespaces.php
-rwxr-xr-x    1 root     root           765 Feb 10 12:03 autoload_psr4.php
-rwxr-xr-x    1 root     root          2414 Feb 10 12:03 autoload_real.php # <-----
-rwxr-xr-x    1 root     root         93179 Feb 10 12:03 autoload_static.php
-rwxr-xr-x    1 root     root         48783 Feb 10 12:03 installed.json


当在我的(windows)开发环境中执行测试时(其中src/目录安装到srv/api/上,通过docker-compose exec php bin/phpunit执行),一切都按预期工作。

编辑:

# Run from where i ran  ls -al vendor/composer/../symfony/phpunit-bridge
$ pwd
/srv/api

$ ls -la /srv
total 12
drwxr-xr-x    1 root     root          4096 Feb 21 13:16 .
drwxr-xr-x    1 root     root          4096 Feb 21 13:17 ..
drwxr-xr-x    1 root     root          4096 Feb 21 13:17 api

jfewjypa

jfewjypa1#

ffouillet's answer带我走上了正确的道路。
即使在使用composer重新安装symfony/phpunit-bridge之后,我也无法通过bin/phpunit运行测试。我不得不直接调用simple-phpunit脚本。
我最终在我的Dockerfile中添加了一个测试镜像的构建步骤,其中:

ENTRYPOINT ["./vendor/bin/simple-phpunit"]
CMD ["--coverage-text"]

字符串

anhgbhbe

anhgbhbe2#

有同样的问题,但与Windows Wamp环境(我复制粘贴我的项目源代码从linux到windows)。我设法解决了这个问题,通过删除symfony/phpunit-bridge(composer remove),然后手动删除.phpunit目录和我的项目bin目录中的phpunit文件,然后重新安装symfony/phpunit-bridge与composer。希望这能有所帮助。

vcudknz3

vcudknz33#

我在兰多也犯过同样的错误
解决方案非常简单(我亲自在appserver容器内执行了所有这些操作)

  • 删除供应商文件夹rm -rf vendor/
  • 重新安装所有composer install
  • 运行Symfony命令bin/simple-phpunit(在第一次执行时,此命令首先安装所有必要的php-unit相关包)

就这样。希望对你也有用。

相关问题