简体   繁体   English

在 PhpStorm 上安装 PHPUnit

[英]PHPUnit installation on PhpStorm

I am trying to use PHPUnit with PhpSTORM by loading it from autoloader file.我试图通过从自动加载器文件加载 PHPUnit 和 PhpSTORM 来使用它。 But, as you can see in the below screenshot, PHPUnit version: is not installed, i am getting the same even if i choose other two options.但是,正如您在下面的屏幕截图中所看到的,未安装 PHPUnit 版本:即使我选择了其他两个选项,我也会得到相同的结果。 ie Path to phpunit.phar and Load from include path(PEAR).即 phpunit.phar 的路径和从包含路径(PEAR)加载。

在此处输入图片说明

here is what i get when i run a test case:这是我运行测试用例时得到的结果: 在此处输入图片说明

PhpUnit classes and code autocompletion is being detected but PhpStorm editor just fine.正在检测 PhpUnit 类和代码自动完成,但 PhpStorm 编辑器很好。

If this happens and you see the red I with PHPUnit Version not installed then you probably get the message "Please select PHP Interpreter to load PHPUnit version" when you press the refresh button.如果发生这种情况并且您在未安装 PHPUnit 版本的情况下看到红色的 I,那么当您按下刷新按钮时,您可能会收到消息“请选择 PHP 解释器以加载 PHPUnit 版本”。

If you have the path to phpunit.phar set and your path the composer autoloader is fine, then it is possible that PHPStorm simply doesn't get what PHP exe file to use to load the PHPUnit.如果您设置了phpunit.phar的路径并且您的phpunit.phar自动加载器路径正常,那么 PHPStorm 可能根本无法获取用于加载 PHPUnit 的 PHP exe 文件。

You can then choose to add a Remote PHP Interpreter but you may also choose to add a local PHP Interpreter (for instance if you have XAMPP or WAMPP or LAMPP installed on your computer).然后您可以选择添加远程 PHP 解释器,但您也可以选择添加本地 PHP 解释器(例如,如果您的计算机上安装了 XAMPP 或 WAMPP 或 LAMPP)。

Press Ctrl+Alt+S and go to -> Languages & Frameworks -> PHP -> CLI Interpreter -> go for the button with the dots (or shift + enter) and there you can add an "Interpreter" by pressing the + button.按 Ctrl+Alt+S 并转到 -> Languages & Frameworks -> PHP -> CLI Interpreter -> 找到带点的按钮(或 shift + enter),然后您可以通过按 + 按钮添加“解释器” .

I added my own local interpreter xampp\\php\\php.exe Press apply and okay and go back to Languages & Frameworks -> PHP -> Test Frameworks and go for the refresh button.我添加了我自己的本地解释器xampp\\php\\php.exe按应用并确定并返回语言和框架 -> PHP -> 测试框架并点击刷新按钮。 It should do some magic and then it will say PHPUnit version: 6.5 (or whichever you installed).它应该做一些魔术,然后它会说 PHPUnit version: 6.5 (或您安装的任何版本)。 I had my local (XAMPP) Apache server running.我的本地 (XAMPP) Apache 服务器正在运行。

For anyone running into this in 2020 and also if you have problem with Docker container mapping, Path Mapping stay same if you select your Project root in Docker container option:对于在 2020 年遇到此问题的任何人,如果您在Docker 容器映射方面遇到问题,如果您在Docker 容器选项中选择项目根目录,路径映射将保持不变:

Just add double slash at your host path: //, looks like this is bug in PHPStorm.只需在您的主机路径添加双斜杠://,看起来这是 PHPStorm 中的错误。

docker 容器 PHPStorm 配置

PHPSTOrm 测试框架配置

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

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