Jens Wegar
Jens Wegar

Reputation: 4872

How do I run multiple versions of PHPUnit on the same machine?

I'm using Zend Framework for some projects and want to build up PHPUnit test suites for them. Unfortunately, Zend Framework in it's current version (1.11.x) only supports PHPUnit 3.5. At the same time, I would also like to start working with the Symfony framework, which in turn supports newer versions of PHPUnit. The question then is, how can I run multiple versions of PHPUnit on my dev machine at the same time without having to install separate servers or things like that?

I'm running OS X Lion (10.7) and using apache and php (5.3.10) installed through MacPorts. Ideally, I would like to end up in a situation where I could simply type e.g. phpunit5 in the terminal to execute the 3.5 version and type phpunit6 to execute the 3.6 version, and so on.

Upvotes: 7

Views: 1815

Answers (3)

Potherca
Potherca

Reputation: 14640

PHPUnit now offers bundled PHAR files for all of it's versions at https://phar.phpunit.de/

Simply download the needed version(s) and call them using:

php phpunit-X.Y.Z.phar  

(Where X.Y.Z is the PHPUnit version)

The PHAR files can easily be aliased to make them available system-wide.

Upvotes: 0

Jens Wegar
Jens Wegar

Reputation: 4872

The accepted answer works when you install phpunit 3.4, but if you wish to install phpunit 3.5 (which can also be used to unit test within a Zend project, although Zends own tests may not all pass) you have to follow a slightly different path. You will need to install the dependencies for phpunit 3.5 separately before installing phpunit, otherwise some of the dependencies will simply force an install of phpunit 3.6:

Install first (note the -f option, which forces installation of a specific version):

sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.symfony-project.com/YAML-1.0.2
sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.phpunit.de/PHPUnit_Selenium-1.0.1
sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.phpunit.de/PHP_Timer-1.0.0
sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.phpunit.de/Text_Template-1.0.0
sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.phpunit.de/PHPUnit_MockObject-1.0.3
sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.phpunit.de/File_Iterator-1.2.3
sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.phpunit.de/PHP_CodeCoverage-1.0.2
sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.phpunit.de/DbUnit-1.0.0
sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.phpunit.de/PHPUnit-3.5.15

Then follow the instructions in the link of the accepted answer to change the include path and symlink it correctly.

Upvotes: 1

Till
Till

Reputation: 22436

I'd recommend you check this blog post:

For a chef-recipe, check my blog post:

In case the links stop working:

  • pear supports an --installroot switch
  • example:

    pear install --installroot /some/path/phpunit34 pear.phpunit.de/PHPUnit-3.4.15

Once install, you may have to add /some/path/phpunit34/usr/bin/ to $PATH or create a symlink to /usr/bin like the blog post illustrates.

HTH

Upvotes: 4

Related Questions