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 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计