PHPUnit-won';找不到我的测试文件或直接执行它们

PHPUnit-won';找不到我的测试文件或直接执行它们,php,phpunit,Php,Phpunit,我的PHPUnit是通过Composer(PHPUnit 3.7.21)安装的。 我有以下目录结构: . ├── Code ├── Test │   ├── Php │   │   └── PlanningModuleTest.php │   └── bootstrap.php └── phpunit.xml 当我执行 $ phpunit 从项目根目录中,我得到以下输出: PHPUnit 3.7.21 by Sebastian Bergmann. Configuration read fr

我的PHPUnit是通过Composer(PHPUnit 3.7.21)安装的。
我有以下目录结构:

.
├── Code
├── Test
│   ├── Php
│   │   └── PlanningModuleTest.php
│   └── bootstrap.php
└── phpunit.xml
当我执行

$ phpunit
从项目根目录中,我得到以下输出:

PHPUnit 3.7.21 by Sebastian Bergmann.

Configuration read from D:\Development\...\phpunit.xml

Time: 40 ms, Memory: 4.00MB

No tests executed!
我的
phpunit.xml
如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
    colors="true"
    bootstrap="Test/bootstrap.php"
>
    <testsuites>
        <testsuite name="pms">
            <directory  suffix="Test.php">./Test/Php/</directory>
        </testsuite>
    </testsuites>
    <php>
        <ini name="display_errors" value="true"/>
    </php>
</phpunit>
project> phpunit
<testsuite name="pms">
    <directory>Test/Php</directory>
</testsuite>
这应该是正确的,因为PHPUnit检查文件和类名是否以Test.php结尾

为什么不执行我的测试

编辑 我试着直接使用

$ phpunit --verbose --debug Test\Php\PlanningModuleTest.php
它返回这个:

Class 'Test\Php\PlanningModuleTest' could not be found in 'D:\Development\Git\projectmanagement\Test\Php\PlanningModuleTest.php'.`

必须从项目目录中使用phpunit命令,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
    colors="true"
    bootstrap="Test/bootstrap.php"
>
    <testsuites>
        <testsuite name="pms">
            <directory  suffix="Test.php">./Test/Php/</directory>
        </testsuite>
    </testsuites>
    <php>
        <ini name="display_errors" value="true"/>
    </php>
</phpunit>
project> phpunit
<testsuite name="pms">
    <directory>Test/Php</directory>
</testsuite>
此外,您的测试套件必须如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
    colors="true"
    bootstrap="Test/bootstrap.php"
>
    <testsuites>
        <testsuite name="pms">
            <directory  suffix="Test.php">./Test/Php/</directory>
        </testsuite>
    </testsuites>
    <php>
        <ini name="display_errors" value="true"/>
    </php>
</phpunit>
project> phpunit
<testsuite name="pms">
    <directory>Test/Php</directory>
</testsuite>

测试/Php

正如评论中所建议的,在我们开始调试与使用全局安装的
phpunit
版本相关的问题之前,请尝试运行

$ ./vendor/bin/phpunit
相反

首先引人注目的是,测试类缺少一个名称空间,而它似乎应该有一个名称空间:

<?php

namespace Test\Php;

use jamesiarmes\PhpEws\Enumeration\UnindexedFieldURIType;
use PHPUnit\Framework\TestCase;

class PlanningModuleTest extends TestCase
{
    // ...
}
由于您尚未与我们共享,请确保
Test/bootstrap.php
包含

<?php

require_once __DIR__ . '/../vendor/autoload.php';

看起来您正在使用至少
phpunit/phpunit:^4.8
,因为您的测试类是从
phpunit\Framework\TestCase
扩展而来的。但是,您的输出表明您正在运行不同版本的
phpunit
。您应该运行
/vendor/bin/phpunit
以使用随
composer
安装的
phpunit
版本。如果找不到类
Test\Php\PlanningModuleTest
,您可以与我们共享文件
Test/bootstrap.Php
的内容吗,但是,如果您确实为特定项目使用与
composer
一起安装的
phpunit
版本,则更有意义。如果您这样做,您需要运行
/vendor/bin/phpunit
(或者如果您使用该选项,它安装到的任何位置)。当我运行
.\code\vendor\bin\phpunit
时,我会收到一个与我的应用程序相关的不同错误。当我回到我的开发机器时,我将进一步调查。出于某种原因,XAMMP(我用来承载我的代码)有一个非常旧的PHPUnit可执行文件,它添加到路径中。我错误地认为PHPUnit是由Composer在全球范围内安装的,但事实并非如此。正如我已经提到的,我现在发现了我的测试,因为我收到了一个与应用程序相关的错误,这是我自己的问题。谢谢