使用 Composer 安装 PHPUNIT

2022-08-30 23:03:53

我在Symfony 2上有项目,我想在Windows 7上使用PHPUNIT。

On githut phpunit is:

Composer

Simply add a dependency on phpunit/phpunit to your project's composer.json file if you use Composer to manage the dependencies of your project. Here is a minimal example of a composer.json file that just defines a development-time dependency on PHPUnit 3.7:

{
    "require-dev": {
        "phpunit/phpunit": "3.7.*"
    }
}
For a system-wide installation via Composer, you can run:

composer global require 'phpunit/phpunit=3.7.*'
Make sure you have ~/.composer/vendor/bin/ in your path.

首先,我使用系统范围的安装,但我不知道何时安装。接下来,我添加到我的 composer.json require-dev。这在C:/wamp/www/myproject/vendor/symfony中安装了phpunit。接下来我尝试命令:

 composer install --dev

我不能使用phpunit。在cmd.exe我输入“phpunit”,我有错误:

'phpunit' is not recognized as an internal or external command operable program or batch file

我如何使用 phpunit?我有Windows 7,Wamp服务器和php 5.4.12。


答案 1

当您通过 composer 在 Windows 中安装 PHP-Unit 时,全局安装将在

C:\Users\YOUR_USERNAME\AppData\Roaming\Composer

要通过命令行轻松执行,您需要在Windows环境变量中添加文件路径。为此:phpunitphpunit.bat

  1. 右键单击My Computer
  2. 转到和Properties -> Advance system settings
  3. 从选项卡中单击。Environment variablesAdvance

现在添加到窗口。C:\Users\YOUR_USERNAME\AppData\Roaming\Composer\vendor\binPATH

您现在可以从命令运行 phpunit。请注意,您可能需要重新启动命令提示符才能使更改生效。


答案 2

包的 bin 文件放在配置的 bin 目录中。默认情况下,这是,当您使用symfony标准版时,这是文件夹。vendor/binbin

要执行此 bin 文件,请运行(或在不使用 Symfony 标准版时运行)./bin/phpunit./vendor/bin/phpunit

Windows用户必须将其放在双引号中:(或"bin/phpunit""vendor/bin/phpunit")


推荐