Laravel 4 测试;'phpunit' 无法识别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16138050/
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-09-14 07:43:42  来源:igfitidea点击:

Laravel 4 testing; 'phpunit' is not recognized?

phpphpunitlaravel

提问by Farzher

http://four.laravel.com/docs/testingSays "After installing a new Laravel application, simply run phpuniton the command line to run your tests."

http://four.laravel.com/docs/testing说“安装新的 Laravel 应用程序后,只需phpunit在命令行上运行即可运行测试。”

phpunitisn't recognized, I also tried php artisian testand php artisan phpunit

phpunit不认可,我也尝试过php artisian testphp artisan phpunit

Is phpunitin some weird folder, or is it actually not included with Laravel? I don't want to install it and have two if it is.

phpunit在某个奇怪的文件夹中,还是 Laravel 中实际上不包含它?我不想安装它,如果是的话就安装两个。

回答by duellsy

Install with composer

使用 Composer 安装

An easy way to get up and running with PHPUnit (without needing to install Pear and clutter up every system you want to use this on) is to include it in your composer.json file, like

使用 PHPUnit 启动和运行的一种简单方法(无需安装 Pear 并弄乱您想要使用它的每个系统)是将它包含在您的 composer.json 文件中,例如

"phpunit/phpunit": "4.0.*",

Then after doing a composer updateyou'll be able to run PHPUnit from command line like this:

然后在做完之后,composer update你就可以像这样从命令行运行 PHPUnit:

vendor/bin/phpunit 

Since phpunit will be installed into the vendor/bin folder.

由于 phpunit 将安装到 vendor/bin 文件夹中。

This will install PHPUnit to this project only, not your whole system. So when you want it gone, you simply remove the line from your composer.json file, run composer update, and poof, not a trace.

这只会将 PHPUnit 安装到这个项目,而不是整个系统。因此,当您想要它消失时,您只需从 composer.json 文件中删除该行,运行 composer update 和 poof,而不是跟踪。

Installing for development environments only

仅为开发环境安装

If you only want to use this during development, add the composer line inside the "require-dev" section. That way it will only be installed when you opt to install dev dependancies via:

如果您只想在开发期间使用它,请在“require-dev”部分中添加 composer 行。这样它只会在您选择通过以下方式安装开发依赖项时安装:

php composer.phar install --dev

or

或者

php composer.phar update

回答by Emeka Mbah

If you are a window user and you are having this issue, do this:

如果您是窗口用户并且遇到此问题,请执行以下操作:

You need to tell Window where to find PHPUnit command, you can first of all verify that this file exists in your Laravel project under /vendor/bin

你需要告诉Window在哪里可以找到PHPUnit命令,你可以首先验证这个文件存在于你的Laravel项目/vendor/bin下

enter image description here

enter image description here

Finally you need to append the full path to /vendor/binin your window PATH variable,

最后,您需要/vendor/bin在窗口 PATH 变量中附加完整路径,

To do this: 1. Right-click on 'Computer' then click properties

为此: 1. 右键单击​​“计算机”,然后单击属性

enter image description here

enter image description here

  1. On the second window click Advanced system settings
  1. 在第二个窗口点击 Advanced system settings

enter image description here

enter image description here

  1. On the next window under Advancedclick Environmental Variables
  1. 在下一个窗口Advanced点击Environmental Variables

enter image description here

enter image description here

  1. On the next window double-click PATHthen set PATH variable by appending
  1. 在下一个窗口中双击,PATH然后通过附加设置 PATH 变量

the full path to your laravel-project/vendor/bin;Notice the ;at the end.

最后的laravel-project/vendor/bin;通知的完整路径;

NB: Other variables might already exists in the PATH, so ensure you don't overwrite them by appending your own at the very end

注意:PATH 中可能已经存在其他变量,因此请确保不要通过在最后添加自己的变量来覆盖它们

  1. Finally click Okon all the dialog boxes
  1. 最后点击Ok所有对话框

enter image description here

enter image description here

回答by Maurice Lagan

The easiest way to use phpunit is to put phpunit.pharin the root of your application and to run it with php phpunit.phar.

使用 phpunit 的最简单方法是将phpunit.phar放在应用程序的根目录中,并使用php phpunit.phar运行它。

回答by Ryan

If you run into "phpunit requires ext-dom" it's because php-xml isn't installed.

如果您遇到“phpunit requires ext-dom”,那是因为未安装 php-xml。

回答by drealecs

You need to install phpunit and the best way is with pear.

您需要安装 phpunit,最好的方法是使用 pear。

pear channel-discover pear.phpunit.de
pear install phpunit/PHPUnit

If you don't have pear installed, check thisregarding pear installation.

如果您没有安装梨执行,检查对于梨安装。