在 Laravel 的 Homestead 中运行 PHPUnit
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28114434/
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
Running PHPUnit in Laravel's Homestead
提问by lesssugar
I'm using Homestead to serve my Laravel application. I'm trying to run PHPUnit. According to the docs:
我正在使用 Homestead 为我的 Laravel 应用程序提供服务。我正在尝试运行 PHPUnit。根据文档:
An example test file is provided in the app/tests directory. After installing a new Laravel application, simply run
phpunit
on the command line to run your tests.
app/tests 目录中提供了一个示例测试文件。安装新的 Laravel 应用程序后,只需
phpunit
在命令行上运行即可运行测试。
Well, when I'm "simply running" phpunit
in my project root (inside the Homestead environment) I get this:
好吧,当我phpunit
在我的项目根目录中(在 Homestead 环境中)“简单地运行”时,我得到了这个:
The program 'phpunit' is currently not installed.
当前未安装程序“phpunit”。
Do I need to install PHPUnit separately then? The documentation does not mention it. What am I doing wrong?
那么我需要单独安装 PHPUnit 吗?文档没有提到它。我究竟做错了什么?
回答by Wader
You can install it globally on the system using.
您可以使用它在系统上全局安装它。
composer global require phpunit/phpunit
However, if you need different versions for different projects this can cause issues.
但是,如果您需要为不同的项目使用不同的版本,这可能会导致问题。
The alternative option is to use the version installed as part of your dependencies by referencing the path to your vendor
directory.
另一种选择是通过引用vendor
目录路径来使用作为依赖项一部分安装的版本。
./vendor/bin/phpunit
You could even add an alias to your aliases file in your ~/Homestead
directory. That way you're always using the phpunit version that is installed with your project dependencies.
您甚至可以为~/Homestead
目录中的别名文件添加别名。这样您就始终使用与项目依赖项一起安装的 phpunit 版本。
alias phpunit=./vendor/bin/phpunit
You'll need to restart the homestead box to make use of the alias.
您需要重新启动宅基地框以使用别名。
回答by Simon Paitrault
You can install it globally with:
您可以使用以下命令全局安装它:
$ composer global require "phpunit/phpunit=4.4.*"
# then use
$ phpunit
or you can use it with your local composer:
或者您可以将它与本地作曲家一起使用:
$ composer require "phpunit/phpunit=4.4.*"
# then
$ vendor/bin/phpunit
回答by Loopsi
Since it's a package required for development, Laravel provide PHPunit(require-dev section in composer), you should find it in vendor's folder :
由于它是开发所需的包,Laravel 提供了 PHPunit(composer 中的 require-dev 部分),您应该在 vendor 文件夹中找到它:
$ your_app/vendor/bin/
You can run the command from the root of your app folder by typing :
您可以通过键入以下命令从应用程序文件夹的根目录运行命令:
$ vendor/bin/phpunit
I hope it will help !
我希望它会有所帮助!