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条回答 默认 最新

  • dongmie3526 2017-02-14 19:19
    关注

    If you're using a composer to manage dependencies then when you run from the root of your project just phpunit you propably execute a global and old phpunit binary.

    You just run tests with:

    PHPUnit 3.7.21 by Sebastian Bergmann.

    Instead of global exec you should run local dependency with the command php ./vendor/bin/phpunit

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置