I recently had a fun idea, that I wanted to try and implement for PHPUnit. I really like coloured console output. PHPUnit already has the option for coloured output, but I wanted more. I wanted to get coloured text for
I that showed up in the test run progress. I also figured this might be something others might want, and that I’d create a patch for PHPUnit.
This of course meant I’d need to get PHPUnit setup using Git. I figured this would be easier, since PHPUnit has recently moved to github. I think there are only a few ways it could be harder. I’m sure Sebastian had the best of intentions when he split up PHPUnit into several repositories. However, it has made working with PHPUnit from Git mildly painful. Since PHPUnit doesn’t use submodules at all, you are left to your own devices to solve its various dependencies. I wanted to work off the master branch, as thats where the next version of PHPUnit looks like it will come from.
I got a great hint in the comments from Matthew Weier O’Phinney. I extended his solution to include all of the various dependencies that PHPUnit has now. In order to be able to contribute back to the master branch I had to do the following.Show Plain Text
- git submodule add git://github.com/sebastianbergmann/php-code-coverage php-code-coverage
- git submodule add git://github.com/sebastianbergmann/php-file-iterator php-file-iterator
- git submodule add git://github.com/sebastianbergmann/php-text-template php-text-template
- git submodule add git://github.com/sebastianbergmann/php-token-stream php-token-stream
- git submodule add git://github.com/sebastianbergmann/php-mock-objects php-mock-objects
- git submodule add git://github.com/sebastianbergmann/dbunit dbunit
- git submodule add git://github.com/sebastianbergmann/phpunit-selenium phpunit-selenium
I then had to go into each submodule and checkout the
master branch for each submodule, as they checkout the
1.0 branch by default. Once I had all the dependencies added as submodules in a local branch I committed it for future use. I then had to add the following to
phpunit.php so I could run PHPUnit’s test suite.
- __DIR__ . '/php-code-coverage/',
- __DIR__ . '/php-file-iterator/',
- __DIR__ . '/php-text-template/',
- __DIR__ . '/phpunit-mock-objects/',
- __DIR__ . '/php-token-stream/',
- __DIR__ . '/dbunit/',
- __DIR__ . '/phpunit-selenium/',
After all this, I was finally able to create my patch, and ensure that I didn’t break anything by running the tests. I’ve pushed both the submodules changes as well as the fancier coloured progress change to github for anyone else is interested in using them.
PHPUnit is a fantastic tool, and I’m really grateful that Sebastian writes and maintains it, but getting setup so you can contribute is a total pain. My suggestion would be to use use submodules to easy getting the right dependencies. Alternatively a script could be made that links everything up so you can contribute and give back to PHPUnit.