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
Laravel 4 testing; 'phpunit' is not recognized?
提问by Farzher
http://four.laravel.com/docs/testingSays "After installing a new Laravel application, simply run phpunit
on the command line to run your tests."
http://four.laravel.com/docs/testing说“安装新的 Laravel 应用程序后,只需phpunit
在命令行上运行即可运行测试。”
phpunit
isn't recognized, I also tried php artisian test
and php artisan phpunit
phpunit
不认可,我也尝试过php artisian test
和php artisan phpunit
Is phpunit
in 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 update
you'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下
Finally you need to append the full path to /vendor/bin
in your window PATH variable,
最后,您需要/vendor/bin
在窗口 PATH 变量中附加完整路径,
To do this: 1. Right-click on 'Computer' then click properties
为此: 1. 右键单击“计算机”,然后单击属性
- On the second window click
Advanced system settings
- 在第二个窗口点击
Advanced system settings
- On the next window under
Advanced
clickEnvironmental Variables
- 在下一个窗口
Advanced
点击Environmental Variables
- On the next window double-click
PATH
then set PATH variable by appending
- 在下一个窗口中双击,
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 中可能已经存在其他变量,因此请确保不要通过在最后添加自己的变量来覆盖它们
- Finally click
Ok
on all the dialog boxes
- 最后点击
Ok
所有对话框
回答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。