This amazing option will install the lowest versions possible for all your dependencies.
What for? Tests of course!
OK before we get started, don’t forget to update Composer right now if you want to use the new option:
Testing against lowest dependencies
It might not make a lot of sense to test an application against its lowest dependencies, because unless something is done wrong it will be installed with controlled versions.
However, for libraries (or components…) it’s a very good thing.
To give you an example, I wanted to give it a try and ran
composer update --prefer-lowest in PHP-DI’s directory: all hell broke loose… PHPUnit wouldn’t even start.
The reason for this were multiples, but they all boiled down to:
- I used a feature that didn’t yet exist in version X of dependency Y
- or dependency Y had a bug in version X
and I allowed installing that problematic version X in
In the end, I was distributing a library that could not work at all (if people had insane version constraints).
Setting up tests on Travis
Let’s be proactive and use continuous integration to prevent that from happening again.
Here is an example of a
.travis.yml configuration that would run the tests using the lowest dependencies with PHP 5.3.3:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
You’ll notice that we have to run
composer self-update because Travis hasn’t picked up the latest Composer version yet.
Here was the result on Travis:
A new job was added to the build matrix, and this job ran on PHP 5.3.3 with the lowest dependency versions.
If you are interested, have a look at the pull request.