热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

无法在包含路径phpstorm中找到PHPUnit。-CannotfindPHPUnitinincludepathphpstorm

CannotfindPHPUnitinincludepathistheerrormessageIgetwhenItrytorunmycodeinphpstorm

Cannot find PHPUnit in include path is the error message I get when I try to run my code in phpstorm.

在include路径中找不到PHPUnit是我在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(特征、短数组语法等),解释器是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:\ php xampp2 \ php \。exe C:\Users\DELL\AppData\Local\Temp\ ide-phpunit。php——了无配置

C:\xampp2\htdocs\ft-website

C:\ xampp2 \根\ ft-website

Testing started at 2:34 PM ...

测试从下午2:34开始……

Process finished with exit code 1

使用退出代码1完成进程

Cannot find PHPUnit in include path (.;C:\xampp2\php\PEAR)`

无法在包含路径(.;C:\xampp2\php\PEAR)中找到PHPUnit。

5 个解决方案

#1


48  

Just encountered this problem myself.

我自己也遇到过这个问题。

I'm unsure why it is unable to find PHPUnit in the include path (despite the fact that it is there, albeit in all lowercase).

我不确定为什么它不能在include路径中找到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库设置更改为使用自定义加载程序,然后指定到PHPUnit可执行文件的路径。在我的mac上,那是/usr/ local/cellar/php54 /5.4.26/ bin/phpunitit。

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安装为PHPUnit。它之前安装了PHPUnit源代码,这对于PHPStorm中的引用和代码完成是非常好的。我认为这就是PHPStorm不能工作的原因,因为它需要的是php可执行文件而不是php归档文件。

So, I'm moving away from using pear to install PHPUnit, and I'm using composer instead. 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直接打包为我的项目的依赖项,这使得它比系统依赖项更具可移植性。您将需要添加供应商/phpunit/phpunit作为PHP包含路径的PHPStorm首选项。这将达到两个目的:

  1. PHPStorm can find the phpunit executable now
  2. PHPStorm现在可以找到phpunit可执行文件
  3. PHPStorm will index all the PHPUnit classes now, so you'll get auto-complete. Yay!
  4. 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,在右边你有你的包含路径

#2


17  

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.

我在设置中选择了使用自定义的autoloader ->语言和框架-> PHP -> PHPUnit,然后添加/vendor/autoload。php作为自定义自动加载程序的位置。

#3


4  

This is the way to do it without using composer, and using your global phpunit.

这是一种无需使用composer和全局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
  2. 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
  2. PhpStorm首选项-到phpunit的>路径。phar ->选择phpunit phar

enter image description here

  1. That's all, good stuff.
  2. 这些都是好东西。

#4


3  

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”

#5


2  

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.

我在2017年的PHPStorm上遇到了同样的问题。首先进入设置——>语言和框架——> PHP并添加一个远程解释器,然后进入设置——>语言和框架——> PHP -> PHPUnit点击上面的+,然后通过远程解释器点击。如果您正在使用Composer autoloader,那么请输入您的完整的流浪路径到您的autoloader文件。


推荐阅读
author-avatar
aguiladesilvo_502
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有