dongwuxie5112 2017-02-14 19:00
浏览 60
已采纳

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

I'm creating a project where I'm using composer to get all my dependencies. I also use phpunit, where I just migrated my project to phpunit 6.0. Before this change my phpunit always worked correctly.

Before this this I was using the 5.7.13 version.

I'm currently requiring the package in my composer.json like this:

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

I let all my tests extend the \PHPUnit\Framework\TestCase class instead of the PHPUnit_Framework_TestCase class.

My configuration stayed the same, which looks like this:

<?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>

My directory structure looks like this:

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

When opening up a terminal in the root of my project and entering the phpunit command, it gives the following message:

PHPUnit 3.7.21 by Sebastian Bergmann.

Configuration read from C:\Users\Bas\Web_development\ProjectName\phpunit.xml

Time: 30 ms, Memory: 4.00MB

No tests executed!

I've already tried adding the suffix="Test.php" to the directory tag inside the phpunit configuration.

I also tried removing the /vendor/ folder from Composer and installing the packages back by an composer update command.

All my test functions start with the test word.


With the answer from John Smith i'm receiving the following error message:

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" "$@"
  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 C++实现更大的整数类
      • ¥15 Python怎么实现加减乘除乘方和阶乘呀
      • ¥15 centos8-arm64平台编译安装ray分布式计算框架。
      • ¥20 求帮做一个安卓app,用Android Studio制作。需要整个项目文件。
      • ¥15 使用深度学习对于楼梯尺寸进行检测
      • ¥15 特别是3和4 帮帮忙
      • ¥15 C++完成两个子类的构建,基类已给出
      • ¥66 求拉格朗日插值某点的值
      • ¥15 简易的机票预定信息系统
      • ¥15 C++实现对称图形小程序