简体   繁体   English

PHPStorm 8 + PHPUnit 4.2.6错误

[英]PHPStorm 8 + PHPUnit 4.2.6 Error

I can't make PHPUnit 4.2.6 to work with PHPStorm 8 . 我无法使PHPUnit 4.2.6PHPStorm 8一起使用

PHPUnit is loaded as phar inside PHPStorm 8 settings. PHPUnit在PHPStorm 8设置中作为phar加载。

Whenever i try to run unit test in PHPStorm i get this error: 每当我尝试在PHPStorm中运行单元测试时,我都会收到此错误:

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. 当我查看“ide-phpunit.php”时,我发现它试图评估无效代码,因为无效的“substr”函数用法。

So my question is, if someone managed to make PHPUnit 4.2.6 work with PHPStorm 8? 所以我的问题是,如果有人设法使PHPUnit 4.2.6与PHPStorm 8一起工作?

Here is how to "unhack" the IDE to run with phpnunit.phar (4x+) nicely on windows and linux! 这里是如何“解开”IDE与phpnunit.phar(4x +)在Windows和Linux上运行良好!

  1. Download phpunit.phar under php, set your phar location from the IDE -> settings -> phpunit and phar location. 在php下载phpunit.phar,从IDE设置你的phar位置 - >设置 - > phpunit和phar位置。 THEN CLOSE IDE 然后关闭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 . 找到你的插件文件的位置,对于Windows上的php,这将是:\\Program Files (x86)\\JetBrains\\PhpStorm 8.0.3\\plugins\\php\\lib
  3. Open php.jar with winrar and open scripts/phpunit.php . 用winrar打开php.jar并打开scripts/phpunit.php
  4. Comment out all PHPUnit/… require statements, so autoloader can do its job instead of using hardcoded values. 注释掉所有PHPUnit/… require语句,因此自动加载器可以完成其工作而不是使用硬编码值。
  5. Go to public static function init() method. 转到public static function init()方法。
  6. Find the if section with a comment at the end says “awful hack”, screenshot . 在最后找到带有评论的if部分说“awful hack”, 截图
  7. Remove all the amateur hacky stuff and replace it with this, screenshot . 删除所有业余hacky东西,并将其替换为此截图
  8. Save the file, Winrar will prompt you to save the archive, SAVE that one too. 保存文件,Winrar将提示您保存存档,也保存该存档。
  9. Run IDE And Run your tests, coverage. 运行IDE并运行测试,覆盖范围。 Enjoy! 请享用!

Hope this helps some of you out there. 希望这可以帮助你们中的一些人。 I will post the information to their forums as well. 我也会将这些信息发布到他们的论坛。

I got the exact same error, and fixed it like this: 我得到了完全相同的错误,并修复如下:

  1. Installed phpunit using: composer global require phpunit/phpunit 安装phpunit使用: composer global require phpunit/phpunit

  2. Goto phpstorm settings: PHPUnit 转到phpstorm设置:PHPUnit

  3. Select "Use custom autoloader" 选择“使用自定义自动加载器”

    • On Windows: C:\\Users\\[username]\\AppData\\Roaming\\Composer\\vendor\\autoload.php 在Windows上: C:\\Users\\[username]\\AppData\\Roaming\\Composer\\vendor\\autoload.php
    • On Linux: /home/[username]/.composer/vendor/autoload.php 在Linux上:/ /home/[username]/.composer/vendor/autoload.php
    • Or point it to the autoloader of your composer project 或者将其指向作曲家项目的自动加载器

PhpStorm generates special temporary "wrapping" to execute the tests and get the output in the form it understands better. PhpStorm生成特殊的临时“包装”来执行测试并以更好理解的形式获得输出。 In your case it's /private/var/folders/qh/xjz1kr297v34pl6zy70_2rl00000gn/T/ide-phpunit.php . 在你的情况下,它是/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. 由于错误显示存在语法错误,因此首先应该尝试删除它,在下次运行时IDE将创建新的,希望没有这个问题。

If that doesn't help, as suggested in the comments, try downgrading the PHPUnit a few versions back, see if that helps. 如果这没有帮助,正如评论中所建议的那样,尝试将PHPUnit降级几个版本,看看是否有帮助。 Alternatively try reinstalling the PhpStorm. 或者尝试重新安装PhpStorm。 If that doesn't work, you have better chances of finding an answer by reporting an issue to the dev team. 如果这不起作用,您可以通过开发团队报告问题来更好地找到答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM