我如何 运行 在 windows(cmd) 上使用 composer 进行 phpunit 测试
How can I run a phpunit test using composer on windows(cmd)
我想 运行 在我的本地 windows 机器上进行 phpunit 测试..(使用 wamp)..
我已经全局安装了 composer..并且 phpunit 安装在我的本地目录中..
文件夹结构..
_________tests
| |
| |______PagesTest.php
|
|________vendor
|
|______bin
|
|_____phpunit
在我的 localroot(www) 上..我创建了一个 phpunit.xml 文件..
<?xml version="1.0" encoding="UTF-8"?>
<phpunit convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
convertErrorsToExceptions="true"
backupStaticAttributes="false"
processIsolation="false"
stopOnFailure="false"
backupGlobals="false"
syntaxCheck="false"
colors="true">
<testsuites>
<testsuite name="Punta Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
我在 Cmd 上尝试过:
C:\wamp\www\vendor\bin>phpunit PagesTest
输出为
Cannot open file PagesTest.php
而且我不知道如何使用 composer运行 这个 PagesTest.php 文件
好的,PHPUnit 正在 运行ning,但找不到测试文件,因为 Composer Autoloader 未加载。
您可以通过为 PHPUnit 添加一个配置文件来解决这个问题,该配置文件定义属性 bootstrap
并设置 Composer Autoloader 文件。
phpunit.xml.dist
的示例
<?xml version="1.0" encoding="utf-8" ?>
<phpunit bootstrap="./vendor/autoload.php">
<testsuites>
<testsuite name="My Project - TestSuite">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
然后只需 运行 PHPUnit 命令:
$ ./vendor/bin/phpunit
在 Windows 上只需翻转斜杠:C:\> .\vendor\bin\phpunit
PHPUnit 将自动检测配置文件 (phpunit.xml.dist
) 并在 bootstrap 阶段加载 Composer Autoloader。
如果测试 class 位于子目录中,您需要像这样将完整路径传递给它:
phpunit ./tests/PagesTest.php
您可以 运行 phpunit
不带任何参数,这将执行在 phpunit.xml.dist
或 phpunit.xml
文件中配置的测试套件中的所有测试。
要在您的项目中通过 Composer 使用 phpunit
二进制安装,您需要使用它的路径:
./vendor/bin/phpunit ./tests/PagesTest.php
我没有 Windows 安装来测试这个,但也许你必须在调用前加上 php
(比如 php ./vendor/bin/phpunit
)。
我想 运行 在我的本地 windows 机器上进行 phpunit 测试..(使用 wamp)..
我已经全局安装了 composer..并且 phpunit 安装在我的本地目录中..
文件夹结构..
_________tests
| |
| |______PagesTest.php
|
|________vendor
|
|______bin
|
|_____phpunit
在我的 localroot(www) 上..我创建了一个 phpunit.xml 文件..
<?xml version="1.0" encoding="UTF-8"?>
<phpunit convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
convertErrorsToExceptions="true"
backupStaticAttributes="false"
processIsolation="false"
stopOnFailure="false"
backupGlobals="false"
syntaxCheck="false"
colors="true">
<testsuites>
<testsuite name="Punta Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
我在 Cmd 上尝试过:
C:\wamp\www\vendor\bin>phpunit PagesTest
输出为
Cannot open file PagesTest.php
而且我不知道如何使用 composer运行 这个 PagesTest.php 文件
好的,PHPUnit 正在 运行ning,但找不到测试文件,因为 Composer Autoloader 未加载。
您可以通过为 PHPUnit 添加一个配置文件来解决这个问题,该配置文件定义属性 bootstrap
并设置 Composer Autoloader 文件。
phpunit.xml.dist
<?xml version="1.0" encoding="utf-8" ?>
<phpunit bootstrap="./vendor/autoload.php">
<testsuites>
<testsuite name="My Project - TestSuite">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
然后只需 运行 PHPUnit 命令:
$ ./vendor/bin/phpunit
在 Windows 上只需翻转斜杠:C:\> .\vendor\bin\phpunit
PHPUnit 将自动检测配置文件 (phpunit.xml.dist
) 并在 bootstrap 阶段加载 Composer Autoloader。
如果测试 class 位于子目录中,您需要像这样将完整路径传递给它:
phpunit ./tests/PagesTest.php
您可以 运行 phpunit
不带任何参数,这将执行在 phpunit.xml.dist
或 phpunit.xml
文件中配置的测试套件中的所有测试。
要在您的项目中通过 Composer 使用 phpunit
二进制安装,您需要使用它的路径:
./vendor/bin/phpunit ./tests/PagesTest.php
我没有 Windows 安装来测试这个,但也许你必须在调用前加上 php
(比如 php ./vendor/bin/phpunit
)。