使用 Composer 安装 PHPUNIT

2022-01-25 00:00:00 windows wamp php symfony phpunit

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

在 githut 上的 phpunit 是:作曲家如果您使用 Composer 管理项目的依赖项,只需将 phpunit/phpunit 的依赖项添加到项目的 composer.json 文件中.这是一个 composer.json 文件的最小示例,它仅定义了对 PHPUnit 3.7 的开发时依赖项:{需要开发":{phpunit/phpunit":3.7.*"}}对于通过 Composer 进行系统范围的安装,您可以运行:作曲家全局需要'phpunit/phpunit = 3.7.*'确保您的路径中有 ~/.composer/vendor/bin/.

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

 composer install --dev

而且我不能使用 phpunit.在 cmd.exe 我输入phpunit",我有错误:

'phpunit' 不是内部或外部命令可运行程序或批处理文件

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

解决方案

当你通过composer在windows中安装PHP-Unit时,全局安装会在其中创建文件

C:UsersYOUR_USERNAMEAppDataRoamingComposer

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

<块引用>

  1. 右击我的电脑
  2. 转到属性->高级系统设置
  3. 点击Advance标签中的Environment variables.

现在将 C:UsersYOUR_USERNAMEAppDataRoamingComposervendorin 添加到 windows PATH.

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

I have project on Symfony 2 and i would like use PHPUNIT on Windows 7.

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.

First i use system-wide installation but i dont know when this installed. Next i add to my composer.json require-dev. This installed phpunit in C:/wamp/www/myproject/vendor/symfony. Next i try commands:

 composer install --dev

And i can't use phpunit. In cmd.exe i enter "phpunit" and i have error:

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

How can i use phpunit? I have Windows 7, Wamp server and php 5.4.12.

解决方案

When you install PHP-Unit in windows via composer, the global installation will create files in

C:UsersYOUR_USERNAMEAppDataRoamingComposer

To execute phpunit easily via command line you need to add path of phpunit.bat file in windows Environment Variables. For this:

  1. Right click My Computer
  2. Go to Properties -> Advance system settings and
  3. Click Environment variables from the Advance tab.

Now add C:UsersYOUR_USERNAMEAppDataRoamingComposervendorin to the windows PATH.

You can now run the phpunit from command. Note that you may need to restart your command prompt for the changes to take effect.

相关文章