7

when i run

composer require --dev phpunit/phpunit

i get the following message:

composer require --dev phpunit/phpunit
Using version ^6.2 for phpunit/phpunit
./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
- Installation request for sebastian/object-enumerator (locked at 2.0.1) -> satisfiable by sebastian/object-enumerator[2.0.1].
- phpunit/phpunit 6.2.0 requires sebastian/object-enumerator ^3.0.2 -> satisfiable by sebastian/object-enumerator[3.0.2].
- phpunit/phpunit 6.2.1 requires sebastian/object-enumerator ^3.0.2 -> satisfiable by sebastian/object-enumerator[3.0.2].
- phpunit/phpunit 6.2.2 requires sebastian/object-enumerator ^3.0.2 -> satisfiable by sebastian/object-enumerator[3.0.2].
- phpunit/phpunit 6.2.3 requires sebastian/object-enumerator ^3.0.2 -> satisfiable by sebastian/object-enumerator[3.0.2].
- Conclusion: don't install sebastian/object-enumerator 3.0.2
- Installation request for phpunit/phpunit ^6.2 -> satisfiable by phpunit/phpunit[6.2.0, 6.2.1, 6.2.2, 6.2.3].

Installation failed, reverting ./composer.json to its original content.

Here is my composer json file:

"require": {
  "php": "^7.0",
  "laravel/framework": "^5.4",
  "guzzlehttp/guzzle": "^6.3",
  "symfony/psr-http-message-bridge": "^1.0",
  "mcamara/laravel-localization": "^1.2",
  "laravelcollective/html": "^5.4",
  "laravel/socialite": "^3.0",
  "yajra/laravel-datatables-oracle": "^7.9"
},
"require-dev": {
  "fzaninotto/faker": "^1.6",
  "symfony/css-selector": "^3.3",
  "symfony/dom-crawler": "^3.3"
}

I tried to get from version 5.4 above and always get a similar error but with other dependecies, the only version that seems to work is 5.0

1
  • I create a fresh project with your composer.json files (making a composer install) then I launch the command composer require --dev phpunit/phpunit without any problem. Try launching some debugging command as described in the above answer Commented Jul 17, 2017 at 20:37

2 Answers 2

24

Run

$ composer require --dev phpunit/phpunit --update-with-dependencies

See https://getcomposer.org/doc/03-cli.md#require:

--update-with-dependencies: Also update dependencies of the newly required packages.

Note Deleting composer.lock in circumstances like this isn't really the best idea, as it might pull in dependencies that break your code in other places. You really only want to update a specific dependency at a time, rather than update all of them at once.

Sign up to request clarification or add additional context in comments.

Comments

2

If you run a composer update with the composer.lock file and the vendor folder present, Composer will take the installed versions into accounts before updating.

Make sure you have the lock file committed into your project repository, to be able to restore the current version. Then try another update, but before that delete the lock file and vendor folder.

My experience is that such an update will not be affected by already installed versions which may prevent the necessary updates.

Another option for debugging the dependencies is to use composer why-not phpunit/phpunit 6.2.0 (use an explicit version you know exists - without version the output of the command is not meaningful). Composer will give you a list of dependencies that prevent the update, for you to investigate further.

5 Comments

no, no and no again do not solve this by deleting the lock file! there is a reason for it, if you force yourself to solve this without deleting you will learn why it is there! Rule of thumb: if you run composer update phpunit/phpunit only phpunit is whitelisted for update. In your case this will not work due to other dependencies, so whitelist them as well and run again in this case composer update phpunit/phpunit sebastian/object-enumerator - repeat this until successfull. You may also combine this with the above mentioned why-not, then you know in advance what to whitelist for update
@NormanM Your approach is assuming that updating is generally evil and will break the software if any unexpected package is also updated. This may be the case here, and it is a danger if no tests exists. On the other hand it will complicate a relatively straighforward process, because the software should be able to specify it's dependencies, and any conscious update effort should be able to update anything as long as it conforms to the requirements. Run the tests, see if it still works, then commit the lock file. Otherwise fetch the backup from the vcs and return to a known working version.
@Sven and your approach is assuming that every 3rd party library is also developed with this great care and that your tests in packages cover all unexpected changes of 3rd party dependencies as well. Try this approach in real situations where hundreds of packages are involved and every change has to be legally documented and tested - not to mention that there are hundreds of parallel branches - who tells you that some merges are not lowering versions again - this might slip through in code review/testing.
Actually this is not only composer.lock but also the shim within the vendor folder. deleting the vendor folder triggers a full update from top of my head if you call composer update. Anyway, keep backups (of the vendor folder) if this causes really issues, which should lead to the point that the project is using dependencies it can't rely on. Remove these. Yes, refactoring time. @NormanM: If you don't expect third-party libs are done that way (developed with great care) why do you require them?!
I agree with @NormanM, deleting composer.lock to solve problems like this isn't the best idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.