2017-02-14 19:00
浏览 56


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"
        <testsuite name="Unit Tests">

My directory structure looks like this:

│   └───bas
│       └───ProjectName
│           └───... source files
│   └───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");

dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/phpunit" "$@"
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongmie3526
    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

    点赞 评论