PHPStorm 8 + PHPUnit 4.2.6 Error

I can not do PHPUnit 4.2.6 to work with PHPStorm 8 .

PHPUnit loads as phar in the settings of PHPStorm 8.

Whenever I try to run unit test in PHPStorm, I get this error:

Parse error: syntax error, unexpected '}' in /private/var/folders/qh/xjz1kr297v34pl6zy70_2rl00000gn/T/ide-phpunit.php(171) : eval()'d code on line 1 Call Stack: 0.0006 344584 1. {main}() /private/var/folders/qh/xjz1kr297v34pl6zy70_2rl00000gn/T/ide-phpunit.php:0 0.0007 344880 2. IDE_PHPUnit_Loader::init() /private/var/folders/qh/xjz1kr297v34pl6zy70_2rl00000gn/T/ide-phpunit.php:194 Warning: require_once(PHPUnit/Runner/Version.php): failed to open stream: No such file or directory in /private/var/folders/qh/xjz1kr297v34pl6zy70_2rl00000gn/T/ide-phpunit.php on line 49 

When I looked at ide-phpunit.php, I found that it was trying to determine the wrong code due to the inappropriate use of the substr function.

So my question is: if someone managed to get PHPUnit 4.2.6 to work with PHPStorm 8?

+4
source share
3 answers

PhpStorm generates a special temporary “package” to run the tests and get the result in a form that it understands best. In your case, this is /private/var/folders/qh/xjz1kr297v34pl6zy70_2rl00000gn/T/ide-phpunit.php . Since the error indicates a syntax error, the first thing you should try is to remove it, the next time you start the IDE will create a new one, hopefully without this problem.

If this does not help, as suggested in the comments, try redefining PHPUnit several versions back, see if this helps. Also try reinstalling PhpStorm. If this does not work, you have a better chance of finding an answer to the problem message to the development team.

+2
source

Here's how to “unzip” an IDE to work with phpnunit.phar (4x +) nicely on windows and linux!

  • Download phpunit.phar under php, set your phar location from IDE -> settings -> phpunit and phar location. THEN CLOSE IDE
  • Find where your plugin files are located, for php on windows it will be :\Program Files (x86)\JetBrains\PhpStorm 8.0.3\plugins\php\lib .
  • Open php.jar with winrar and open scripts/phpunit.php .
  • Comment on everything PHPUnit/… require, so the autoloader can do its job instead of using hardcoded values.
  • Go to the public static function init() method.
  • Find the if section with a comment at the end that says “terrible hacking,” a screenshot .
  • Remove all amateur hacker stuff and replace them with a screenshot .
  • Save the file, Winrar will offer you to save the archive, SAVE too.
  • Run the IDE and run your coverage tests. Enjoy it!

Hope this helps some of you there. I will also post information on my forums.

+3
source

I got the same error and fixed it like this:

  • Installed phpunit with: composer global require phpunit/phpunit

  • Go to phpstorm settings: PHPUnit

  • Select Use Custom Autoloader

    • On Windows: C:\Users\[username]\AppData\Roaming\Composer\vendor\autoload.php
    • On Linux: /home/[username]/.composer/vendor/autoload.php
    • Or point it to the autoloader of your composer project.
+3
source

All Articles