Getting PHPUnit setup from Git

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 F, E, S, and 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
  1. git submodule add git://github.com/sebastianbergmann/php-code-coverage php-code-coverage
  2. git submodule add git://github.com/sebastianbergmann/php-file-iterator php-file-iterator
  3. git submodule add git://github.com/sebastianbergmann/php-text-template php-text-template
  4. git submodule add git://github.com/sebastianbergmann/php-token-stream php-token-stream
  5. git submodule add git://github.com/sebastianbergmann/php-mock-objects php-mock-objects
  6. git submodule add git://github.com/sebastianbergmann/dbunit dbunit
  7. 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.

Show Plain Text
  1. set_include_path(implode(PATH_SEPARATOR, array(
  2. __DIR__,
  3. __DIR__ . '/php-code-coverage/',
  4. __DIR__ . '/php-file-iterator/',
  5. __DIR__ . '/php-text-template/',
  6. __DIR__ . '/phpunit-mock-objects/',
  7. __DIR__ . '/php-token-stream/',
  8. __DIR__ . '/dbunit/',
  9. __DIR__ . '/phpunit-selenium/',
  10. )));

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.

Comments

PHPUnit is one of the main reasons I am anticipating CakePHP 2.0! Thanks for shining some light on the painful checkout process, hopefully this will get resolved at some point.

James Fuller on 12/11/10

As soon as I have some more time (end-of-the-year crazyness plus final work on the English edition of the #phpqabook), I will work on submodules for PHPUnit’s Git repository to make it easier to contribute.

Sebastian Bergmann on 12/12/10

Cool! Justone note – git’s parameter ‘-b’ works for ‘git submodule add’ just like for ‘git clone’.

100rk on 12/12/10

Sebastian: That’s awesome news. I didn’t intend to come across as complaining, and I’d be willing to help out if you want a hand in getting the submodules setup.

mark story on 12/12/10

This post is almost two years old; is this still the recommended way to install phpunit and all its dependencies from github? Or is there an alternative now?

D on 10/5/12

D: I don’t know if this process still works. Getting PHPUnit setup from git was more complicated the last time I tried sadly.

mark story on 10/15/12

> This post is almost two years old; is this still the
> recommended way to install phpunit and all its dependencies
> from github? Or is there an alternative now?

I have made an installer that worked today (30.12.2012) https://github.com/kblomqvist/gitinstall-phpunit

kblomqvist on 12/30/12

Comments are not open at this time.