Running multiple versions of PHPUnit
The latest version of PHPUnit (3.6.4 at the time of this writing) does not play well with the Zend Framework extensions (Zend_Test_PHPUnit). After asking Matthew Weier O’Phinney about this he answered that they had standardized on PHPUnit-3.4 for ZF1.
Having just upgraded to the latest version of PHPUnit on our servers we were no longer able to test our Zend Framework applications. One option was to downgrade PHPUnit, but since we were already using some of the new features this was not going to happen.
One solution to this problem is to run multiple versions of PHPUnit and use specific versions for specific test suites. Not optimal, but at least it gets the job done.
Installing multiple versions can be accomplished by using the
--installroot option to the
sudo pear config-set auto_discover 1 sudo pear install --installroot /some/path/phpunit34 pear.phpunit.de/PHPUnit-3.4.15
This will install PHPUnit-3.4.15 to
You will need to make a small change to one of the installed files to fix the
include_path. If you installed the package to
/some/path/phpunit34 the file you want to change is
/some/path/phpunit34/usr/bin/phpunit. Before the first
require_once statement in that file, enter the following code:
// Ubuntu / Debian set_include_path(implode(PATH_SEPARATOR, array( dirname(__FILE__) . '/../share/php', get_include_path() ))); // CentOS set_include_path(implode(PATH_SEPARATOR, array( dirname(__FILE__) . '/../share/pear', get_include_path() )));
The path you need to prepend to PHP’s
include_path is different from distro to distro. To see the path your system uses run the following command:
pear config-show|grep php_dir
or simply look around in the directory where you installed the specific version of PHPUnit.
The last part of the puzzle is to place a symlink to the file you just edited in /usr/bin. This can be done by running the following command:
sudo ln -s /some/path/phpunit34/usr/bin/phpunit /usr/bin/phpunit34
To verify that everything works you can run these commands:
christere@spongebob:~$ phpunit --version PHPUnit 3.6.4 by Sebastian Bergmann. christere@spongebob:~$ phpunit34 --version PHPUnit 3.4.15 by Sebastian Bergmann.
Feel free to leave a comment if you see any possible problems with this solution.