如何更新 phpunit 6 和代码覆盖率 5
Posted
技术标签:
【中文标题】如何更新 phpunit 6 和代码覆盖率 5【英文标题】:How to update phpunit 6 and code-coverage 5 【发布时间】:2020-03-11 10:06:31 【问题描述】:我正在使用 phpunit 6.5.14 和 php-code-coverage 5.3.2
我想更新 phpunit 和 php-code-coverage。但是,当我尝试更新其中一个时,它会失败,因为它们彼此需要。
例如。打电话
composer require --dev phpunit/phpunit ^7
失败:
1/1: http://repo.packagist.org/p/provider-latest$f1c1ff74699130b4d82cd11e43a57fffc27fdcc5f268000782f585b13d1c5d4c.json
Finished: success: 1, skipped: 0, failure: 0, total: 1
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Conclusion: don't install phpunit/phpunit 7.5.17
- Conclusion: don't install phpunit/phpunit 7.5.16
- Conclusion: don't install phpunit/phpunit 7.5.15
- Conclusion: don't install phpunit/phpunit 7.5.14
- Conclusion: don't install phpunit/phpunit 7.5.13
- Conclusion: don't install phpunit/phpunit 7.5.12
- Conclusion: don't install phpunit/phpunit 7.5.11
- Conclusion: don't install phpunit/phpunit 7.5.10
- Conclusion: don't install phpunit/phpunit 7.5.9
- Conclusion: don't install phpunit/phpunit 7.5.8
- Conclusion: don't install phpunit/phpunit 7.5.7
- Conclusion: don't install phpunit/phpunit 7.5.6
- Conclusion: don't install phpunit/phpunit 7.5.5
- Conclusion: don't install phpunit/phpunit 7.5.4
- Conclusion: don't install phpunit/phpunit 7.5.3
- Conclusion: don't install phpunit/phpunit 7.5.2
- Conclusion: don't install phpunit/phpunit 7.5.1
- Conclusion: don't install phpunit/phpunit 7.5.0
- Conclusion: don't install phpunit/phpunit 7.4.5
- Conclusion: don't install phpunit/phpunit 7.4.4
- Conclusion: don't install phpunit/phpunit 7.4.3
- Conclusion: don't install phpunit/phpunit 7.4.2
- Conclusion: don't install phpunit/phpunit 7.4.1
- Conclusion: don't install phpunit/phpunit 7.4.0
- Conclusion: don't install phpunit/phpunit 7.3.5
- Conclusion: don't install phpunit/phpunit 7.3.4
- Conclusion: don't install phpunit/phpunit 7.3.3
- Conclusion: don't install phpunit/phpunit 7.3.2
- Conclusion: don't install phpunit/phpunit 7.3.1
- Conclusion: don't install phpunit/phpunit 7.3.0
- Conclusion: don't install phpunit/phpunit 7.2.7
- Conclusion: don't install phpunit/phpunit 7.2.6
- Conclusion: don't install phpunit/phpunit 7.2.5
- Conclusion: don't install phpunit/phpunit 7.2.4
- Conclusion: don't install phpunit/phpunit 7.2.3
- Conclusion: don't install phpunit/phpunit 7.2.2
- Conclusion: don't install phpunit/phpunit 7.2.1
- Conclusion: don't install phpunit/phpunit 7.2.0
- Conclusion: don't install phpunit/phpunit 7.1.5
- Conclusion: don't install phpunit/phpunit 7.1.4
- Conclusion: don't install phpunit/phpunit 7.1.3
- Conclusion: don't install phpunit/phpunit 7.1.2
- Conclusion: don't install phpunit/phpunit 7.1.1
- Conclusion: don't install phpunit/phpunit 7.1.0
- Conclusion: don't install phpunit/phpunit 7.0.3
- Conclusion: don't install phpunit/phpunit 7.0.2
- Conclusion: don't install phpunit/phpunit 7.0.1
- Conclusion: remove phpunit/php-code-coverage 5.3.2
- Installation request for phpunit/phpunit-mock-objects (locked at 5.0.10) -> satisfiable by phpunit/phpunit-mock-objects[5.0.10].
- Installation request for phpunit/phpunit ^7 -> satisfiable by phpunit/phpunit[7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.2.7, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 7.3.4, 7.3.5, 7.4.0, 7.4.1, 7.4.2, 7.4.3, 7.4.4, 7.4.5, 7.5.0, 7.5.1, 7.5.10, 7.5.11, 7.5.12, 7.5.13, 7.5.14, 7.5.15, 7.5.16, 7.5.17, 7.5.2, 7.5.3, 7.5.4, 7.5.5, 7.5.6, 7.5.7, 7.5.8, 7.5.9].
- Conclusion: don't install phpunit/php-code-coverage 5.3.2
- phpunit/phpunit 7.0.0 requires phpunit/php-code-coverage ^6.0 -> satisfiable by phpunit/php-code-coverage[6.0.0, 6.0.1, 6.0.2, 6.0.3, 6.0.4, 6.0.5, 6.0.6, 6.0.7, 6.0.8, 6.1.0, 6.1.1, 6.1.2, 6.1.3, 6.1.4].
- Can only install one of: phpunit/php-code-coverage[6.0.0, 5.3.2].
- Can only install one of: phpunit/php-code-coverage[6.0.1, 5.3.2].
- Can only install one of: phpunit/php-code-coverage[6.0.2, 5.3.2].
- Can only install one of: phpunit/php-code-coverage[6.0.3, 5.3.2].
- Can only install one of: phpunit/php-code-coverage[6.0.4, 5.3.2].
- Can only install one of: phpunit/php-code-coverage[6.0.5, 5.3.2].
- Can only install one of: phpunit/php-code-coverage[6.0.6, 5.3.2].
- Can only install one of: phpunit/php-code-coverage[6.0.7, 5.3.2].
- Can only install one of: phpunit/php-code-coverage[6.0.8, 5.3.2].
- Can only install one of: phpunit/php-code-coverage[6.1.0, 5.3.2].
- Can only install one of: phpunit/php-code-coverage[6.1.1, 5.3.2].
- Can only install one of: phpunit/php-code-coverage[6.1.2, 5.3.2].
- Can only install one of: phpunit/php-code-coverage[6.1.3, 5.3.2].
- Can only install one of: phpunit/php-code-coverage[6.1.4, 5.3.2].
- Installation request for phpunit/php-code-coverage (locked at 5.3.2) -> satisfiable by phpunit/php-code-coverage[5.3.2].
尝试通过
更新代码覆盖率composer require phpunit/php-code-coverage ^6
失败:
1/3: http://repo.packagist.org/p/provider-2019-10$1fbc8abf3f09ae347d28fffd902e6857758ba1084d91f9a81432e2a4039456fa.json
2/3: http://repo.packagist.org/p/provider-latest$b45915c1d4dfb4884956884c1468dfdd815ecef36ccfcbfe487b1bde9b209131.json
3/3: http://repo.packagist.org/p/provider-2019-07$645a5eaea36f8c8ff4b02534eb6864a423517398ecd77c4709effcb55d4a0c07.json
Finished: success: 3, skipped: 0, failure: 0, total: 3
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- phpunit/phpunit 6.5.14 requires phpunit/php-code-coverage ^5.3 -> satisfiable by phpunit/php-code-coverage[5.3.0, 5.3.1, 5.3.2, 5.3.x-dev] but these conflict with your requirements or minimum-stability.
- phpunit/phpunit 6.5.14 requires phpunit/php-code-coverage ^5.3 -> satisfiable by phpunit/php-code-coverage[5.3.0, 5.3.1, 5.3.2, 5.3.x-dev] but these conflict with your requirements or minimum-stability.
- phpunit/phpunit 6.5.14 requires phpunit/php-code-coverage ^5.3 -> satisfiable by phpunit/php-code-coverage[5.3.0, 5.3.1, 5.3.2, 5.3.x-dev] but these conflict with your requirements or minimum-stability.
- Installation request for phpunit/phpunit (locked at 6.5.14, required as ~6.0) -> satisfiable by phpunit/phpunit[6.5.14].
Installation failed, reverting ./composer.json to its original content.
我还尝试删除代码覆盖,以便我可以更新 php-unit 并重新安装它。但是用
删除它composer remove phpunit/php-code-coverage
不起作用,只是给出这个通知:
phpunit/php-code-coverage is not required in your composer.json and has not been removed
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
ocramius/package-versions: Generating version class...
ocramius/package-versions: ...done generating version class
Carbon 1 is deprecated, see how to migrate to Carbon 2.
https://carbon.nesbot.com/docs/#api-carbon-2
You can run './vendor/bin/upgrade-carbon' to get help in updating carbon and other frameworks and libraries that depend on it.
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover
Discovered Package: arrilot/laravel-widgets
Discovered Package: barryvdh/laravel-debugbar
Discovered Package: fideloper/proxy
Discovered Package: intervention/image
Discovered Package: iwasherefirst2/laravel-multimail
Discovered Package: larapack/voyager-hooks
Discovered Package: laravel/tinker
Discovered Package: mcamara/laravel-localization
Discovered Package: nunomaduro/larastan
Discovered Package: spatie/laravel-sitemap
Discovered Package: tcg/voyager
Discovered Package: xethron/migrations-generator
Package manifest generated successfully.
如何更新这两个包?
【问题讨论】:
【参考方案1】:我建议删除 composer.lock
和或 vendor
,因为 Composer 在这方面并不完美。通常根本没有冲突。
然后更改从composer.json
中删除两个包。
然后让作曲家重新决定可能的最高版本:
composer require phpunit/phpunit
您可以省略 phpunit/php-code-coverage
,因为它已经在 phpunit/phpunit
required packages 中。
【讨论】:
您好,谢谢您的回答。我按照您的建议删除了composer.lock
和vendor
。我没有在我的composer.json
中手动添加任何包,它们是我正在使用的包Laravel
的依赖项。它很奇怪,但是package actually required phpunit~7.0,所以我不确定为什么作曲家首先安装 6.5.14。如果我尝试如上所述强制 ^7,我会得到同样的错误。
您好,您能否将composer.json
提供给原始帖子?我去看看
我仔细看了看,composer.json
是版本6
手动需要的包。您的解决方案效果很好。
太好了,很高兴听到这个消息!
我认为 composer 在这里是正确的,好像需要特定版本一样,它需要最好的外观来满足命令的要求。只是当发生冲突时,通常会出现多个冲突,并且输出往往会变得压倒性的。您可以要求通过更新单个包来更新依赖项。 phpunit 应该领先于代码覆盖率。【参考方案2】:
我用--update-with-dependencies
解决了这个问题:
$ composer require --dev --update-with-dependencies phpunit/phpunit ^7.0.0
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 12 updates, 1 removal
- Removing phpunit/phpunit-mock-objects (5.0.10)
- Updating sebastian/resource-operations (1.0.0 => 2.0.1): Downloading (100%)
- Updating sebastian/environment (3.1.0 => 4.2.3): Downloading (100%)
- Updating sebastian/diff (2.0.1 => 3.0.2): Downloading (100%)
- Updating sebastian/comparator (2.1.3 => 3.0.2): Downloading (100%)
- Updating phpunit/php-timer (1.0.9 => 2.1.2): Downloading (100%)
- Updating phpunit/php-file-iterator (1.4.5 => 2.0.2): Downloading (100%)
- Updating phpunit/php-token-stream (2.0.2 => 3.1.1): Downloading (100%)
- Updating phpunit/php-code-coverage (5.3.2 => 6.1.4): Downloading (100%)
- Updating phar-io/version (1.0.1 => 2.0.1): Downloading (100%)
- Updating phar-io/manifest (1.0.1 => 1.0.3): Downloading (100%)
- Updating phpunit/phpunit (6.5.14 => 7.5.20): Downloading (100%)
(我通过https://github.com/composer/composer/issues/3063找到了这个选项)
【讨论】:
以上是关于如何更新 phpunit 6 和代码覆盖率 5的主要内容,如果未能解决你的问题,请参考以下文章
Laravel 5:PHPUnit 和没有可用的代码覆盖驱动程序
在 laravel 4.2 项目上运行具有代码覆盖率的 phpunit 时的空目录
markdown [代码覆盖率Phpunit]安装Xdebug并使用Phpunit运行代码覆盖率#xdebug #phpunit #code #coverage