php 在包含路径 phpstorm 中找不到 PHPUnit
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18310259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot find PHPUnit in include path phpstorm
提问by Newtt
Cannot find PHPUnit in include path
is the error message I get when I try to run my code in phpstorm.
Cannot find PHPUnit in include path
是我尝试在 phpstorm 中运行我的代码时收到的错误消息。
In the PHP Settings, my PHP level language is 5.4 (traits, short array syntax, etc.)
and interpreter is Name(5.4.7)
where Name
is user defined.
在PHP设置,我的PHP高级语言是5.4 (traits, short array syntax, etc.)
和解释器Name(5.4.7)
哪里Name
是用户定义的。
The error appears when I try to run the code and the exact message is this:
当我尝试运行代码时出现错误,确切消息是这样的:
C:\xampp2\php\php.exe C:\Users\DELL\AppData\Local\Temp\ide-phpunit.php --no-configuration
C:\xampp2\htdocs\ft-website
Testing started at 2:34 PM ...
Process finished with exit code 1
Cannot find PHPUnit in include path (.;C:\xampp2\php\PEAR)`
C:\xampp2\php\php.exe C:\Users\DELL\AppData\Local\Temp\ide-phpunit.php --no-configuration
C:\xampp2\htdocs\ft-website
测试于下午 2:34 开始......
进程以退出代码 1 结束
在包含路径中找不到 PHPUnit (.;C:\xampp2\php\PEAR)`
回答by Ben
Just encountered this problem myself.
自己刚遇到这个问题。
I'm unsure why it is unable to find PHPUnit in the include path (despite the fact that it isthere, albeit in all lowercase).
我不确定为什么在包含路径中找不到 PHPUnit(尽管它在那里,尽管都是小写)。
I got around this by changing my IntelliJ Preferences for PHPUnit (under PHP --> PHPUnit
). I changed the PHPUnit library
settings to Use custom loader
and then specified the path to the phpunit
executable. On my mac, that was /usr/local/Cellar/php54/5.4.26/bin/phpunit
.
我通过更改 PHPUnit 的 IntelliJ 首选项(在 下PHP --> PHPUnit
)解决了这个问题。我将PHPUnit library
设置更改为Use custom loader
,然后指定了phpunit
可执行文件的路径。在我的 Mac 上,那是/usr/local/Cellar/php54/5.4.26/bin/phpunit
.
UPDATE:
更新:
I just discovered that pear
now installs PHPUnit as a phar
named phpunit
. It previously installed the PHPUnit source, which was really nice for reference and code completion in PHPStorm. I think that this is the reason things aren't working any longer with PHPStorm, because it's expecting a php executable and not a php archive.
我刚刚发现pear
现在将 PHPUnit 安装为一个phar
命名的phpunit
. 它之前安装了 PHPUnit 源代码,非常适合 PHPStorm 中的参考和代码补全。我认为这就是 PHPStorm 不再起作用的原因,因为它需要一个 php 可执行文件而不是一个 php 存档。
So, I'm moving away from using pear
to install PHPUnit, and I'm using composerinstead. This bundles PHPUnit directly as a dependency of my project, which makes it more portable than a system dependency. You'll need to add vendor/phpunit/phpunit
as a PHP include path in your PHPStorm preferences. This will serve two purposes:
所以,我不再使用pear
安装 PHPUnit,而是使用composer。这将 PHPUnit 直接捆绑为我的项目的依赖项,这使其比系统依赖项更具可移植性。您需要vendor/phpunit/phpunit
在 PHPStorm 首选项中添加为 PHP 包含路径。这将有两个目的:
- PHPStorm can find the
phpunit
executable now - PHPStorm will index all the
PHPUnit
classes now, so you'll get auto-complete. Yay!
- PHPStorm
phpunit
现在可以找到可执行文件 - PHPStorm
PHPUnit
现在将索引所有类,因此您将获得自动完成功能。好极了!
To do this, go to Languages and Frameworks in the PhpStorm settings. If you click on PHP, on the right you have your include paths
为此,请转到 PhpStorm 设置中的语言和框架。如果你点击 PHP,在右边你有你的包含路径
回答by Matt Gibson
I had this problem after adding PHPUnit via composer.
通过 Composer 添加 PHPUnit 后,我遇到了这个问题。
I fixed this by choosing use custom autoloader
in Settings -> Languages and Frameworks -> PHP -> PHPUnit
, then adding /vendor/autoload.php as the location of the custom autoloader.
我通过选择use custom autoloader
in 来解决这个问题Settings -> Languages and Frameworks -> PHP -> PHPUnit
,然后添加 /vendor/autoload.php 作为自定义自动加载器的位置。
回答by a20
This is the way to do it without using composer, and using your global phpunit.
这是不使用作曲家和使用全局 phpunit 的方法。
- Phpunit now comes with a phar file. My path was /usr/local/Cellar/phpunit/5.0.0/libexec/phpunit-5.0.0.phar
- Phpunit 现在带有一个 phar 文件。我的路径是/usr/local/Cellar/phpunit/5.0.0/libexec/phpunit-5.0.0.phar
- PhpStorm Preferences ->Path to phpunit.phar ->select the phpunit phar
- PhpStorm Preferences ->phpunit.phar 的路径->选择 phpunit phar
- That's all, good stuff.
- 就这些,好东西。
回答by fabs
In addition to Ben's answer, in phpStorm 7.1.3 it works by specifying the phpunit.phar location under the "use custom loader" option, for example:
除了 Ben 的回答,在 phpStorm 7.1.3 中,它通过在“使用自定义加载器”选项下指定 phpunit.phar 位置来工作,例如:
"Path to script: /usr/share/php/phpunit.phar"
“脚本路径:/usr/share/php/phpunit.phar”
回答by styl3r
I had this same problem for PHPStorm 2017 using Vagrant. First go to Settings -> Languages and Frameworks -> PHP
and Add a remote interpreter, then go to Settings -> Languages and Frameworks -> PHP -> PHPUnit
click the + on top and click by Remote Interpreter
. If you're using Composer autoloader, then enter your full Vagrant path to your autoloader file.
我在使用 Vagrant 的 PHPStorm 2017 中遇到了同样的问题。首先转到Settings -> Languages and Frameworks -> PHP
并添加远程解释器,然后Settings -> Languages and Frameworks -> PHP -> PHPUnit
单击顶部的 + 并单击by Remote Interpreter
。如果你使用 Composer 自动加载器,那么输入你的自动加载器文件的完整 Vagrant 路径。
回答by jgangso
For future readers, to fix the same issue when using PHPStorm + Vagrant + PHPUnit by defining path to the global phpunit.phar(not composer)
对于未来的读者,通过定义全局 phpunit.phar(不是 composer)的路径来解决使用 PHPStorm + Vagrant + PHPUnit 时的相同问题
While the tests runned successfully, I was missing the code completion. I had confirmed that phpunit
was in the PATH on my local machine, and to make sure, I had added /usr/local/bin
to the PHP Include paths in PHP Settings
. Still no code completion.
虽然测试成功运行,但我错过了代码完成。我证实,phpunit
是在我的本地机器上的路径,以确保,我已经加入/usr/local/bin
到PHP包含路径中PHP Settings
。仍然没有代码完成。
The reason: PHPstorm was looking for phpunit.phar
, not just phpunit
. To fix, on my local machine I established a symlink phpunit.phar
pointing to phpunit
:
原因:PHPstorm 正在寻找phpunit.phar
,而不仅仅是phpunit
. 为了修复,在我的本地机器上,我建立了一个phpunit.phar
指向的符号链接phpunit
:
$ cd /usr/local/bin/
$ sudo ln -s phpunit phpunit.phar
Then I reindexed the project, and code completion started working.
然后我重新索引了项目,代码完成开始工作。