简体   繁体   中英

How to composer install latest of require-dev and lowest for require

I want to run tests for the lowest support version of the packages installed using composer, but I ideally want the development packages at the latest versions.

Specifically, I want to run this to install the lowest version of packages for the purpose of testing:

composer update --prefer-lowest --prefer-stable

However, this will also downgrade PHPUnit and other development packages, which may cause tests to fail because of bugs in those development packages.

I can get more explicit with version required of each development package, however, whilst I may want to test my package with the lowest version of the packages it uses, it never makes sense to run these tests with lower versions of PHPUnit and other development packages.

Is there a way to force require to --prefer-lowest whilst keeping require-dev at the latest?

The --no-dev flag skips the development packages for install|require|update operations.

  1. Update to get the latest versions of application ( require ) and development ( require-dev ) packages:

     composer update --no-autoloader 
  2. Run the following command to downgrade your application dependencies ( require ) to the lowest stable versions but use --no-dev to prevent downgrading the development dependencies ( require-dev ).

     composer update --no-dev --prefer-lowest --prefer-stable --no-autoloader 
  3. Dump the autoloader for require and require-dev packages.

     composer dump-autoload 

The simplest solution is to use correct constraints for development packages. If your tests requires PHPUnit 8.3.4 to run correctly and may fail on 8.3.3, use ^8.3.4 as a constraint for phpunit/phpunit package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM