PHPStorm 8 + PHPUnit 4.2.6 Error

无人久伴 提交于 2019-12-20 01:43:29

问题


I can't make PHPUnit 4.2.6 to work with PHPStorm 8.

PHPUnit is loaded as phar inside PHPStorm 8 settings.

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 into "ide-phpunit.php", i found that it tries to eval invalid code, because of invalid "substr" function usage.

So my question is, if someone managed to make PHPUnit 4.2.6 work with PHPStorm 8?


回答1:


PhpStorm generates special temporary "wrapping" to execute the tests and get the output in the form it understands better. In your case it's /private/var/folders/qh/xjz1kr297v34pl6zy70_2rl00000gn/T/ide-phpunit.php. Since the error says there is a syntax error, the first thing you should try is deleting it, on the next run the IDE will create the new one, hopefully without that problem.

If that doesn't help, as suggested in the comments, try downgrading the PHPUnit a few versions back, see if that helps. Alternatively try reinstalling the PhpStorm. If that doesn't work, you have better chances of finding an answer by reporting an issue to the dev team.




回答2:


Here is how to "unhack" the IDE to run with phpnunit.phar (4x+) nicely on windows and linux!

  1. Download phpunit.phar under php, set your phar location from the IDE -> settings -> phpunit and phar location. THEN CLOSE IDE
  2. Find where your plugin files are, for php on windows this would be :\Program Files (x86)\JetBrains\PhpStorm 8.0.3\plugins\php\lib.
  3. Open php.jar with winrar and open scripts/phpunit.php.
  4. Comment out all PHPUnit/… require statements, so autoloader can do its job instead of using hardcoded values.
  5. Go to public static function init() method.
  6. Find the if section with a comment at the end says “awful hack”, screenshot.
  7. Remove all the amateur hacky stuff and replace it with this, screenshot.
  8. Save the file, Winrar will prompt you to save the archive, SAVE that one too.
  9. Run IDE And Run your tests, coverage. Enjoy!

Hope this helps some of you out there. I will post the information to their forums as well.




回答3:


I got the exact same error, and fixed it like this:

  1. Installed phpunit using: composer global require phpunit/phpunit

  2. Goto phpstorm settings: PHPUnit

  3. 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


来源:https://stackoverflow.com/questions/25910328/phpstorm-8-phpunit-4-2-6-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!