如何从 Windows 命令提示符在 Laravel 中运行 PHPUnit

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

How do I run PHPUnit in Laravel from my Windows Command prompt

phplaravellaravel-5phpunit

提问by Jaime Dolor jr.

I have a Laravel app installed in my directory f:\lara_app. I use PHP artisan serve to run the app. I have Laravel version 5.4.36 (via Composer Install)

我在我的目录 f:\lara_app 中安装了一个 Laravel 应用程序。我使用 PHP artisan serve 来运行该应用程序。我有 Laravel 版本 5.4.36(通过 Composer 安装)

I am not trying my hand in using the PHP Unit to do testing. Inside f:/lara_app/tests/Unit/ExampleTest.php, I have the following codes:

我并没有尝试使用 PHP 单元进行测试。在 f:/lara_app/tests/Unit/ExampleTest.php 中,我有以下代码:

namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
         $this->assertTrue(true);
    }

    public function myFirstTest()
    {
        $value = 'Hello World';
        $this->assertTrue( 'Hello' === $value, 'Value should be Hello World');
    }     
}

I now try to run the test from my command prompt:

我现在尝试从我的命令提示符运行测试:

f:\lara_app> .vendor/phpunit/phpuni/phpunit

But I'm getting the message below:

但我收到以下消息:

'.vendor' is not recognized as an internal or external command, operable program or batch file

'.vendor' 不是内部或外部命令,也不是可运行的程序或批处理文件

How do I run the PHPUnit test?

如何运行 PHPUnit 测试?

Thanks in advance

提前致谢

回答by Nikolay Oskin

Use quotes:

使用引号:

"./vendor/bin/phpunit"

回答by Marcus

This should work on windows

这应该适用于 Windows

f:\lara_app> php vendor/phpunit/phpunit/phpunit

回答by Manford Benjamin

This works for me

这对我有用

C:\code\project-name> vendor\bin\phpunit

回答by Edrich

Also for future readers, you can run it on windows powershell, without having to change anything, if you're in the root directory of your project. Simply Type

同样对于未来的读者,如果您位于项目的根目录中,您可以在 windows powershell 上运行它,而无需更改任何内容。只需键入

./vendor/bin/phpunit

回答by Mahdi Naderian

For every Laravel project, if you want to run tests you can do one of these:

对于每个 Laravel 项目,如果您想运行测试,您可以执行以下操作之一:

  • You can use artisan:php artisan test
  • Or you can use phpunit:if you want to run phpunit on windows, only by typing phpunit, you can create a bat file in your project's main directory by running this command:@echo php vendor\phpunit\phpunit\phpunit > phpunit.batand then you can type phpunitin your command and enjoy.
  • 您可以使用工匠:php artisan test
  • 或者你可以使用phpunit:如果你想在windows上运行phpunit,只需要输入phpunit,你就可以通过运行这个命令在你的项目的主目录中创建一个bat文件:@echo php vendor\phpunit\phpunit\phpunit > phpunit.bat然后你可以输入phpunit你的命令并享受。

Happy Testing...

快乐测试...