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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:19:34  来源:igfitidea点击:

Cannot find PHPUnit in include path phpstorm

phpphpstorm

提问by Newtt

Cannot find PHPUnit in include pathis 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 Nameis 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 librarysettings to Use custom loaderand then specified the path to the phpunitexecutable. 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 pearnow installs PHPUnit as a pharnamed 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 pearto 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/phpunitas a PHP include path in your PHPStorm preferences. This will serve two purposes:

所以,我不再使用pear安装 PHPUnit,而是使用composer。这将 PHPUnit 直接捆绑为我的项目的依赖项,这使其比系统依赖项更具可移植性。您需要vendor/phpunit/phpunit在 PHPStorm 首选项中添加为 PHP 包含路径。这将有两个目的:

  1. PHPStorm can find the phpunitexecutable now
  2. PHPStorm will index all the PHPUnitclasses now, so you'll get auto-complete. Yay!
  1. PHPStormphpunit现在可以找到可执行文件
  2. PHPStormPHPUnit现在将索引所有类,因此您将获得自动完成功能。好极了!

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 autoloaderin Settings -> Languages and Frameworks -> PHP -> PHPUnit, then adding /vendor/autoload.php as the location of the custom autoloader.

我通过选择use custom autoloaderin 来解决这个问题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 的方法。

  1. Phpunit now comes with a phar file. My path was /usr/local/Cellar/phpunit/5.0.0/libexec/phpunit-5.0.0.phar
  1. Phpunit 现在带有一个 phar 文件。我的路径是/usr/local/Cellar/phpunit/5.0.0/libexec/phpunit-5.0.0.phar

enter image description here

在此处输入图片说明

  1. PhpStorm Preferences ->Path to phpunit.phar ->select the phpunit phar
  1. PhpStorm Preferences ->phpunit.phar 的路径->选择 phpunit phar

enter image description here

在此处输入图片说明

  1. That's all, good stuff.
  1. 就这些,好东西。

回答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 -> PHPand Add a remote interpreter, then go to Settings -> Languages and Frameworks -> PHP -> PHPUnitclick 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 phpunitwas in the PATH on my local machine, and to make sure, I had added /usr/local/binto 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.pharpointing 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.

然后我重新索引了项目,代码完成开始工作。