作为项目的一部分安装时执行 PHPUnit

Execute PHPUnit when is installed as part of a project

我已将 composer 添加到独立项目中:

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

在我 运行 composer require "phpunit/phpunit=5.4.*" --dev 之后,库安装在 vendor/ 下。我写了一个小测试用例,我把它放在 tests/CollectionTest.php 下,我想 运行 它但是 ....

# phpunit
bash: phpunit: command not found

# phpunit --bootstrap vendor/autoload.php tests
bash: phpunit: command not found

我还添加了这个:

~/.composer/vendor/bin/

~/.bash_rc 文件。我错过了什么?如何执行测试用例?

您应该在 bin 目录中找到 ./vendor/phpunit/phpunit/phpunit 路径的别名。所以尝试:

>bin/phpunit

>vendor/phpunit/phpunit/phpunit

希望对您有所帮助

PHPUnit 安装在项目目录的 vendor 文件夹中,而不是全局目录中。尝试 cd 到您的项目目录和 运行 PHPUnit by:

$ cd /{project-directory}
$ ./vendor/bin/phpunit

可以使用 phpunit.xml file.

配置详细的测试设置