安装pear时如何修复错误以安装phpunit?

I am not quite sure if the question belongs to this forum, so if not and you are about to close this question, please make a suggestion where else to ask this question.

Basically, I need to install phpunit on Ubuntu 12.04. By doing so with the packet manager I get an error when running phpunit:

PHP Fatal error:  require_once(): Failed opening required 'PHP/CodeCoverage/Filter.php' (include_path='.:/usr/share/php:/usr/share/pear') in /usr/bin/phpunit on line 38

for which there are solutions, i.e. to install phpunit with pear.

Following the pear install instructions I download and run go-pear.phar, which itself produces an error

PHP Notice:  Uninitialized string offset: 0 in phar:///home/alexander/opt/src/go-pear.phar/Console/Getopt.php on line 145

Any suggestions how to proceed from here? I also ONLY need phpunit, so pear will be used just for this case once.

The installation of phpunit really seems to be extremly complicated and circumstantial, but here is the solution:

  • As for Ubuntu 12.04 pear should be already installed
  • However, the latest version of pear should be used
  • And phpunit need to be removed before it is reinstalled

The whole procedure and each step is described on symfony-world, one might need the additional step shown in the given comment. Here is a copy-and-paste of the complete procedure for Ubuntu 12.04:

sudo apt-get remove phpunit
sudo apt-get upgrade pear
sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover pear.symfony-project.com
sudo pear channel-discover components.ez.no
sudo pear channel-discover pear.symfony.com
sudo pear update-channels
sudo pear upgrade-all
sudo pear install --alldeps phpunit/PHPUnit

if you need only phpunit, use composer.. For example composer.json may look like:

{
    "require-dev": {
        "phpunit/phpunit": "3.7.*"
    }
}