33
votes

I am running tests in PhpStorm and I get this error. Does anyone know what on earth could be causing it?

PHP Fatal error: Class 'PHPUnit_TextUI_ResultPrinter' not found in C:\Users\administrator1\AppData\Local\Temp\ide-phpunit.php on line 249

I run tests in other projects - that also utilise ide-phpunit.php and they run just fine.

10
PHPUnit version? What kind of installation it is (PHAR/Composer)? PhpStorm version?LazyOne
I figured out the issue (answer below). In the interests of helping Googlers that are troubleshooting this issue though it was a composer install, phpunit 3.7, PhpStorm 9 :)b85411

10 Answers

26
votes

I had the same issue with Ubuntu 16.10, phpStorm 2017.2 and Laravel 5.5

Fixed it by uninstalling phpunit from my Ubuntu-system with

sudo apt-get remove phpunit
sudo apt-get install --autoremove

or for mac:

brew uninstall phpunit
brew install phpunit

My PhpStorm configuration (File -> Settings -> Languages & Frameworks -> PHP -> Test Frameworks):

phpStorm-Configuration

Works great, now!

13
votes

Silly mistake on my part... simply forgot to add phpunit as a dependency in the project. For anyone else that gets this error, to composer.json add:

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

And then run:

composer update

That solved the problem.

11
votes

In my case the problem was caused by following set of reasons:

  1. I installed phpunit using composer with composer require phpunit/phpunit command. I did not pay attention that by default it used php7 and it installed phpunit6 which has class names with namespaces (PHPUnit\TextUI\ResultPrinter).
  2. IDE runs old version of phpunit which expects class names without namespaces (PHPUnit_TextUI_ResultPrinter)

I decided to reinstall phpunit running same composer command as above, but under php 5.6 (because it was important to be compatible with php5.6) and it installed phpunit 5.7 . But it is possible to go with newer version of phpunit and php: Settings > PHP > PHPUnit :: "Use composer autoloader" (set path to phpunit executable inside vendors (it was vendors/bin/phpunit in my case))

7
votes

I got this error while using the various modifier-F10 keys in PHPStorm, because it didn't know where to find the correct PHPUnit.

In settings (ctrl-alt-s), search for PHPUnit. In my case I wanted to set it as follows:

  • "use composer autoloader"
  • Path to script: full-path-to-project/vendor/autoload.php (this field was empty for me, with an error showing in the dialog)

Otherwise it would try to use some cached version of the library (/tmp/ide-phpunit.php) instead of the composer version. If you prefer to use some globally installed binary, you could of course use the Path to phpunit.phar option.

7
votes

I had same problem with PHP7.1 and PHPUnit 6.3 via composer but I resolved via phpunit.phar. (in the options : select path to phpunit.phar, click on download and click on refresh)

enter image description here

3
votes

After updating to latest composer, composer run-script drupal-phpunit-upgrade, PHPStorm was still mapped to the old version even though I was loading through autoloader. I went to Languages & Frameworks > Php > Test Frameworks and hit the refresh button on the same line as "Path to Script".

Now my PHPUnit version reads 6.5.8.

1
votes

In my case, in phpstorm preferences -> php -> CLI interpreter was set on local, when it needed to use remote php 7 (ubuntu).

Because I use vagrant box to have my environment configured on ubuntu.

0
votes

I recently came across similar error PHPUnit_TextUI_ResultPrinter not found in TeamCity.php on line 19

I am using PhpStorm 2018.3.3. Upon using terminal from PhpStorm $ phpunit PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

from my Ubuntu system $ phpunit --version PHPUnit 5.1.3 by Sebastian Bergmann and contributors.

I had to make sure the my Ubuntu system PHPUnit is updated to 7.5.1. So here's what I did:

sudo wget https://phar.phpunit.de/phpunit-7.5.1.phar
sudo chmod +x phpunit-7.5.1.phar
sudo mv phpunit-7.5.1.phar /usr/local/bin/phpunit

Then I went to PhpStorm: File > Settings > Language & Frameworks > PHP > Test Frameworks and made sure that the PHPUnit version is also 7.5.1

And then from PhpStorm terminal: phpunit and the test cases were running perfectly fine.

0
votes

I went to the settings and set my path to php as follows: (according to the brew)

/usr/local/opt/php/bin/php

Then phpunit works.

-3
votes

I got the same error. Solved by using phpunit4.8 (older version)