PHPUnit无法识别给定目录中的测试

问题描述 投票:0回答:2

我正在创建一个项目,在其中使用composer来获取我的所有依赖关系。我还使用phpunit,在这里我只是将项目迁移到phpunit 6.0。在此更改之前,我的phpunit始终可以正常工作。

在此之前,我使用的是5.7.13版本。

我目前在composer.json中需要这样的包装:

  "require-dev": {
    "phpunit/phpunit": "^6.0"
  },

我让我所有的测试都扩展了\PHPUnit\Framework\TestCase类而不是PHPUnit_Framework_TestCase类。

我的配置保持不变,看起来像这样:

<?xml version="1.0" encoding="UTF-8" ?>
<phpunit bootstrap="vendor/autoload.php"
         color="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         stopOnFailures="false"
         syntaxCheck="false">
    <testsuites>
        <testsuite name="Unit Tests">
            <directory>./tests/bas/ProjectName/</directory>
        </testsuite>
    </testsuites>
</phpunit>

我的目录结构如下:

├───src
│   └───bas
│       └───ProjectName
│           └───... source files
├───tests
│   └───bas
│       └───ProjectName
│           ├───...test files like "ExampleTest.php"

当在我的项目的根目录中打开一个终端并输入phpunit命令时,它会显示以下消息:

Sebastian Bergmann编写的PHPUnit 3.7.21。

读取配置C:\ Users \ Bas \ Web_development \ ProjectName \ phpunit.xml

时间:30毫秒,内存:4.00MB

未执行测试!

我已经尝试过将suffix="Test.php"添加到phpunit配置内的directory标记中。

[我也尝试过从Composer中删除/vendor/文件夹,并通过composer update命令安装软件包。

我所有的测试功能都以test字开头。


使用the answer from John Smith,我收到以下错误消息:

dir=$(d=${0%[/\\]*}; cd "$d"; cd "../phpunit/phpunit" && pwd)

# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
        # Cygwin paths start with /cygdrive/ which will break windows PHP,
        # so we need to translate the dir path to windows format. However
        # we could be using cygwin PHP which does not require this, so we
        # test if the path to PHP starts with /cygdrive/ rather than /usr/bin
        if [[ $(which php) == /cygdrive/* ]]; then
                dir=$(cygpath -m "$dir");
        fi
fi

dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/phpunit" "$@"
php oop phpunit
2个回答
1
投票

如果您使用作曲家来管理依赖项,那么当您从项目的根目录运行phpunit时,可能会执行一个全局的和旧的phpunit二进制文件。

您只需使用以下命令运行测试:

Sebastian Bergmann编写的PHPUnit 3.7.21。

而不是全局执行程序,您应该使用命令php ./vendor/bin/phpunit运行本地依赖项>


0
投票

尝试运行php "vendor/phpunit/phpunit/phpunit"

© www.soinside.com 2019 - 2024. All rights reserved.