4

I have installed phpunit in my ubuntu 11.10 having php version 5.2.14.

But when I run my test module it is throwing error,

PHP Fatal error:  Call to undefined method PHP_CodeCoverage_Filter::getInstance() in /usr/share/php/PHPUnit/Autoload.php on line 64

I followed the steps mention in this stack question but still no luck.

Call to undefined method PHP_CodeCoverage_Filter::getInstance()

Community
  • 1
  • 1
Rikesh
  • 26,156
  • 14
  • 79
  • 87

3 Answers3

6

Following steps solved my problem.

sudo apt-get remove phpunit

sudo pear channel-discover pear.phpunit.de

sudo pear channel-discover pear.symfony.com

sudo pear channel-discover components.ez.no

sudo pear update-channels

sudo pear upgrade-all

sudo pear install --alldeps phpunit/PHPUnit

sudo pear install --force --alldeps phpunit/PHPUnit
Rikesh
  • 26,156
  • 14
  • 79
  • 87
1

One workaround - granted, not really a solution - is to bypass PEAR install and use a local copy via Composer install.

Create a file in project root called composer.json:

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

Of course, modify the phpunit version to "3.6.*" or similar, if you have such a requirement.

At project root:

# Install composer
$ curl -s https://getcomposer.org/installer | php

# Tell composer to install the dependencies identified in composer.json
$ php composer.phar install

# Now you can invoke the *local* copy of phpunit
$ ./vendor/phpunit/phpunit/composer/bin/phpunit --version

For simplicity, you can can create a symlink to the phpunit executable. Assuming you want the symlink in a directory called tests:

$ ln -s ./vendor/phpunit/phpunit/composer/bin/phpunit ./tests/phpunit

Then you can invoke as (from project root):

$ cd tests
$ ./phpunit --version

Even easier, you can direct Composer to handling the symlinking for you. Add this to your composer.json:

"config": {
    "bin-dir": "tests"
}

Then, as before, you can invoke as (from project root):

$ cd tests
$ ./phpunit --version

Actually, what I usually do is have a project-level directory called scripts and point my composer bin-dir there. Then I manually create a symlink in tests pointing to scripts/phpunit. But this last step is probably more personal taste than any kind of requirement.

Maybe a long way to go just to beat PEAR issues, but I find Composer-based install works pretty reliably for me.

David Weinraub
  • 14,144
  • 4
  • 42
  • 64
  • Thanks for answer. I got phpunit installed now from above stack overflow question ref. but now I am getting `Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /usr/share/php/File/Iterator/Autoload.php on line 45 ` error when I run phpunit command. – Rikesh Dec 25 '12 at 13:43
  • A syntax error like that in an downloaded component like PHPUnit sounds like an incomplete download. I'd remove and re-install. – David Weinraub Dec 25 '12 at 14:08
  • 1
    Aaah, I notice you are on PHP 5.2.14. PHPUnit 3.7 requires PHP >= 5.3.3, while PHPUnit 3.6 only requires PHP >= 5.2.7. Unless you have a need to be at PHP 5.2, I'd recommend a boost to 5.3. – David Weinraub Dec 26 '12 at 02:53
  • Yeah I googled & get to know it ( phpunit) only requires PHP >= 5.2.7, but I can't upgrade it.Still searching for some other solution :( ..Thanks for your great help – Rikesh Dec 26 '12 at 05:41
  • You can still use the composer-based install. Just specify `3.6.*` for the phpunit version in `composer.json`. – David Weinraub Dec 26 '12 at 06:29
0

my platform Symfony 1.4 did not have installed the latest version of the plugin that is compatible with latest phpunit version. So updating to latest version of https://github.com/JWT-OSS/sfJwtPhpUnitPlugin/ worked for me.

Muneer
  • 7,384
  • 7
  • 38
  • 62