PHPUnit is one of my favorite unit testing tools and I recently needed to install it directly into a project with composer. I’m on a macbook pro running mavericks and homebrew, so I typed:
composer require "phpunit/phpunit"
Surprisingly, I got:
Could not load package phpspec/prophecy in http://packagist.org: [UnexpectedValueException] Could not parse version constraint ^1.0.2: Invalid version string "^1.0.2"
I looked at my version of composer, installed last year probably, and it was at 1.0.0-alpha8. Aha! I thought, I will upgrade.
brew upgrade composer
This upgraded composer to 1.0.0-alpha9, but still did not resolve the error message.
Finally, the magic to get it working was:
The update set composer to 1.0-dev, which was enough for my composer require “phpunit/phpunit” installation command to work.
I’m noting this tip here on my blog in case anyone else finds themselves working with PHPUnit since the closure of its pear repository last year. Composer is an awesome dependency management tool that’s a delight to use and I’m glad only a quick self-update was needed for PHPUnit.