Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with PHPUnit (Linux) - PHP Fatal Error

I successfully installed PHPUnit on my desktop PC and decided to have it on my laptop PC, but... then I try to create PHPUnit test Netbeans throws an error "Selected PHPUnit (version ?.?.?) is to old, upgrade it if possible (the minimum version is 3.3.0).".

Of course my PHPUnit version is newer - 3.5.5-2. Where is the problem?

I am using

  • Ubuntu 11.04
  • Netbeans 6.9
  • PEAR Version: 1.9.1
  • PHP Version: 5.3.5-1ubuntu7.2
  • Zend Engine Version: 2.3.0

As I understand the problem is with PHPUnit. When I try to call "phpunit" command in terminal I receive PHP Fatal error:

root@ubuntu:~# phpunit –version
PHP Warning:  require_once(PHP/CodeCoverage/Filter.php): failed to open stream: No such file or directory in /usr/bin/phpunit on line 38
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
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
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
root@ubuntu:~# find / -name CodeCov*
root@ubuntu:~#

As you can see there is no such file or folder in my PC. What to do?

I tried to reinstall it many times (with apt-get, pear, Synaptic PM...), but always get the same result.

like image 217
Johnny Avatar asked May 19 '11 18:05

Johnny


3 Answers

Problem solved.

Follow @David Harkness comment I tried to install PHP_CodeCoverage and then I realized that my PEAR Installer is too old. I Upgraded it to 1.9.2 and then reinstalled PHPUnit.

$ wget http://pear.php.net/go-pear.phar
$ php go-pear.phar
$ pear install phpunit/PHPUnit

What's quite strange because all software was freshly installed week ago.

Answer. How I installed PHPUnit finally.

sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover components.ez.no
sudo pear channel-discover pear.symfony-project.com
sudo pear install phpunit/PHP_CodeCoverage
sudo pear install phpunit/PHPUnit

If You still have problems try to update PEAR:

sudo wget http://pear.php.net/go-pear.phar
sudo php go-pear.phar
like image 104
Johnny Avatar answered Nov 01 '22 09:11

Johnny


  1. configure channel autodiscovery

    sudo pear config-set auto_discover 1

  2. simply upgrade / install phpunit with --alldeps flag enabled

    sudo pear upgrade --alldeps channel://pear.phpunit.de/PHPUnit

and it automatically does the necessary magics. :)

Update: http://pear.phpunit.de/ has gone away (Returns 410)

like image 8
acpmasquerade Avatar answered Nov 01 '22 08:11

acpmasquerade


The other solutions here did not work for me. I finally found a solution that worked for me here: http://markojakic.net/configure-phpunit-and-pear-in-ubuntu-12-04

Essentially pear by default for me was installing binaries to my home directory. To fix it I ran the following commands

sudo pear config-set bin_dir /usr/bin
sudo pear config-set doc_dir /usr/share/php/doc
sudo pear config-set php_dir /usr/share/php
sudo pear config-set cfg_dir /usr/share/php/cfg (make (sudo mkdir cfg) directory here)
sudo pear config-set data_dir /usr/share/php/data
sudo pear config-set test_dir /usr/share/php/test

sudo pear uninstall phpunit/PHPUnit
sudo pear install phpunit/PHPUnit
like image 3
drewag Avatar answered Nov 01 '22 09:11

drewag