phpunit 命令不适用于 Windows 7 上的 laravel 4

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

phpunit command doesn't work for laravel 4 on windows 7

phpunit-testinglaravelphpunit

提问by Ramin

I've recently installed laravel and have written some tests in /tests directory but when I use phpunitat cmd in the same folder that phpunit.xmlexists, it says 'phpunit' is not recognized as an internal or external command,operable program or batch file.. I'm using windows 7. what should I do?

我最近安装了 laravel 并在 /tests 目录中编写了一些测试,但是当我phpunitphpunit.xml存在的同一文件夹中使用at cmd时,它说'phpunit' is not recognized as an internal or external command,operable program or batch file.. 我使用的是 Windows 7。我该怎么办?

回答by Chris

The solution for me:

对我来说的解决方案:

php vendor/phpunit/phpunit/phpunit

This, of course, assumes you've set up a php environment variable in Windows

当然,这假设您已经在 Windows 中设置了 php 环境变量

回答by Michael A

As Unnawut said, it doesn't work because vendor/phpunit/phpunit/phpunit is not a native Windows executable. You need a .bat or .cmd file that will basically call 'php phpunit'. There should be one in vendor/bin, but to make life easy, try this - create a file phpunit.bat (or .cmd) at the root of your site, containing this:

正如 Unnawut 所说,它不起作用,因为 vendor/phpunit/phpunit/phpunit 不是本机 Windows 可执行文件。您需要一个 .bat 或 .cmd 文件,它基本上会调用“php phpunit”。在 vendor/bin 中应该有一个,但为了让生活更轻松,请尝试此操作 - 在您的站点根目录创建一个文件 phpunit.bat(或 .cmd),其中包含以下内容:

@ECHO OFF
SET BIN_TARGET=%~dp0/vendor/phpunit/phpunit/phpunit
php "%BIN_TARGET%" %*

Now you can call phpunit from the command line at the root of the site.

现在您可以从站点根目录的命令行调用 phpunit。

回答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

在此处输入图片说明

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

在此处输入图片说明

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

enter image description here

在此处输入图片说明

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

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

在此处输入图片说明

回答by RektByAyyLMAO

alias phpunit="vendor/bin/phpunit"

回答by Unnawut

The phpunit executable is not in your project root folder, that's why it can't find it.

phpunit 可执行文件不在您的项目根文件夹中,这就是它找不到它的原因。

Now I assume that you already have phpunit in your composer.jsonfile, something like this:

现在我假设您的composer.json文件中已经有 phpunit ,如下所示:

"require-dev": {
    "phpunit/phpunit": "3.7.*"
}

When installed by composer, the package will be installed to vendor/vendor_name/package_name. So to run it at your project root, type this command:

当由 composer 安装时,该包将安装到vendor/vendor_name/package_name. 因此,要在您的项目根目录下运行它,请键入以下命令:

vendor/phpunit/phpunit/phpunit

回答by vimuth

I added this command in command line instead of just "phpunit"

我在命令行中添加了这个命令,而不仅仅是“phpunit”

vendor\bin\phpunit

That worked for me.

那对我有用。

回答by Iter Ator

Install phpunitglobally:

phpunit全局安装:

composer global require phpunit/phpunit

Afterwards you will be able to run phpunit( even on Windows ):

之后您将能够运行phpunit(甚至在 Windows 上):

phpunit

回答by Tobi Alafin

Borrowing from @Chris' excellent answer:
Even better, you can make vendor/phpunit/phpunit/phpunitan environment variable, say "phpunit" and whenever you want to run the test in any laravel project you just call php %phpunit%.

借用@Chris 的出色回答
更好的是,您可以创建vendor/phpunit/phpunit/phpunit一个环境变量,例如“phpunit”,并且每当您想在任何 Laravel 项目中运行测试时,只需调用php %phpunit%.

Demonstration

示范

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

回答by davidceranic

If it says the following:

如果它说如下:

$ phpunit tests/Feature/ExampleTest.php PHPUnit 3.7.21 by Sebastian Bergmann.

$ phpunit tests/Feature/ExampleTest.php PHPUnit 3.7.21 by Sebastian Bergmann。

Class 'tests/Feature/ExampleTest' could not be found in 'C:\xampp\htdocs\blog1\tests\Feature\ExampleTest.php'.

在“C:\xampp\htdocs\blog1\tests\Feature\ExampleTest.php”中找不到类“tests/Feature/ExampleTest”。

Instead of typing tests/Feature/ExampleTest.php you say tests " \\Feature\\Example.test" because you're using windows, not mac. :) GL & HF

而不是键入 tests/Feature/ExampleTest.php 你说测试“\\Feature\\Example.test”因为你使用的是windows,而不是mac。:) GL & 高频

Using just \ or / will give errors :)

仅使用 \ 或 / 会出错:)