News Archive
PhpRiot Newsletter
Your Email Address:

More information

Composer Dependency Woes

Note: This article was originally published at Planet PHP on 16 May 2012.
Planet PHP

I spent the better part of this afternoon trying to figure out why a Composer installation wasn't working and finally figured out the problemait wasn't mine.

First, a little context - I'm currently working on a testing presentation for some folks at work and I wanted to show them how to work with the Behat testing tool to create some handy functional/integration tests for our framework-based apps. I threw together a little framework (yes yes, I know) and got the PHPUnit tests set up and running in no time. When it came to the Behat tests, though, no matter what I did, I was still having a problem:

PHP Fatal error: Class 'Goutte\Client' not found in /www/htdocs/testing-examples/app/vendor/behat/mink/src/Behat/Mink/Driver/Goutte/Client.php on line 13

No matter how I tried to configure the composer install, it always gave me this message. I tried everything I could think of and, finally, at the suggestion of Rafael Dohms, checked out the github repository for the Goutte client (a href=a As it turns out, in the past day or so, there's been a large change where Fabien implemented composer support on the repo.

Apparently this was what broke things - thankfully not something obvious I was missing.

So, how did I solve it so I could see the lovely green of passing tests again? Well, if you're familiar with composer, you know there's a composer.lock file that's created after you install. When you run the aocomposer installa and it fetches from aofabpot/gouttea:a*a, you get this latest version that has the issues. A quick modification of the composer.lock file takes care of that though:

{ "package": "fabpot/goutte", "version": "master-dev", "source-reference": "5ecceb7c28a428fb93f283982cc4f5edfd96630b" },

See that aosource-referencea setting? Well, that can either point to the branch or version you want to pull from or it can point to a specific commit. In my case, I just pulled the hash for the commit before all of the changes and dropped it in there. Then it's just a matter of running a aocomposer installa to get the code from this commit instead. Don't run an update though - that will wipe out your manual changes to the lock file and you'll be back to square one.

Hope this helps someone out there who might be dealing with a similar issue regarding brokenness on an external lib!