我已经开始学习如何使用PHPUnit了。但是,我面临一个问题,我不知道如何解决。
我有一个名为lessons
的文件夹,里面有一个composer.json
,我安装了PHPUnit。输出结果是一个名为vendor
的文件夹和一个名为bin
的子文件夹,其中包含phpunit文件。
在cmd
我输入:cd c:/xampp/htdocs/lessons/vendor/bin
。现在cmd文件夹设置为与phpunit相同的文件夹。我在lessons
中创建了一个目录,我将其命名为tests
(lessons/tests
),我将所有测试存储在其中。我创建了一个名为PracticeTest.php
的文件,其中包含一个非常简单的测试脚本。
当我回到cmd
并输入phpunit tests
时,我得到cannot open file tests.php
当我尝试输入phpunit PracticeTest
时,我得到了cannot open file PracticeTest.php
。当我尝试phpunit tests/PracticeTest
(与.php
或没有)时,我得到相同的错误,文件无法打开。
我怀疑它与cmd
指向lessons/vendor/bin
目录的那张脸有关,但我不确定它是否真的是问题或如何解决它。
只是为了安排路径:
lessons\vendor\bin\
lessons\tests\
lessons\tests\PracticeTest.php
提前致谢!
转到路径项目:
D:\>cd www
D:\wwww>cd lessons
并执行:
D:\www\lessons>vendor\bin\phpunit tests
PHPUnit 4.8.27 by Sebastian Bergmann and contributors.
.....E.
Time: 1.34 seconds, Memory: 5.50MB
There was 1 error:
1) UserTest::it_should_be_able_to_construct
PHPUnit_Framework_Exception: Argument #1 (No Value) of PHPUnit_Framework_Assert
:assertInstanceOf() must be a class or interface name
D:\www\lessons\tests\UserTest.php:10
FAILURES!
Tests: 7, Assertions: 4, Errors: 1.
有用!!!!
这对我有用。
vendor/bin/phpunit ./tests/PracticeTest
我有用逗号分隔的include_path
部分。它必须是Windows上的分号。
我在我的项目的根文件夹中创建了一个phpunit.bat
@ECHO OFF SET BIN_TARGET=%~dp0/vendor/phpunit/phpunit/phpunit php "%BIN_TARGET%" %*
现在它有效。