PHP 单元执行所有测试

PHP unit execute all the test

我尝试 运行ning 这个命令:

php bin/phpunit

我收到这个错误:

PHP Fatal error: Uncaught Error: Call to undefined method PHPUnit\TextUI\TestRunner::doRun() in C:\wamp64\www\Test___Hanff_Web\bin.phpunit\phpunit-7.5-0\src\TextUI\Command.php:206

我看到它正在使用 phpunit 7.5,但我在我的 composer.json 中需要 phpunit 9.2 :

// composer.json
"require": {
        "php": "^7.4",
        ...
        "phpunit/phpunit": "^9.2",       <-- here
        "sensio/framework-extra-bundle": "^5.1",
        "spatie/enum": "^2.3",
        "symfony/asset": "^5.1",
        ...
        "symfony/framework-bundle": "5.1.*",
        ...
    },
    "require-dev": {
        "dama/doctrine-test-bundle": "^6.3",
        "doctrine/doctrine-fixtures-bundle": "^3.3",
        "symfony/browser-kit": "^5.1",
        "symfony/css-selector": "^5.1",
        "symfony/debug-pack": "^1.0",
        "symfony/phpunit-bridge": "^5.1",   <-- Also here because symfony doc told me to import that
        "symfony/stopwatch": "^5.1",
        "symfony/twig-bundle": "^5.1",
        "symfony/web-profiler-bundle": "^5.1"
    },

当我尝试执行此操作时:

> vendor\bin\phpunit --version

PHPUnit 9.2.6 by Sebastian Bergmann and contributors.

我得到的是 9.2 版而不是这个 :

> php bin/phpunit --version

PHPUnit 7.5.20 by Sebastian Bergmann and contributors.

所以我尝试 运行 composer update 但它没有改变任何东西。 然后我尝试按照 here 所述自我更新 php 单元,但什么也没做!

我实际上只能通过执行此命令 运行 我的 php 测试 :

> vendor\bin\phpunit tests/Controller/WebTest_ArticleController.php

它在一个 TestCase 文件中执行所有测试,但我无法对所有 tests/* 目录执行所有测试。

我希望能够 运行 我所有的测试 :

> php bin/phpunit

... Runing all test

或类似的东西:

> vendor\bin\phpunit tests/*

... Runing all test in tests/ directory

我也看过这个 但它并没有给我提供任何令人满意的解决方案

你必须使用 vendor\bin\phpunit 并在测试文件夹中将您的测试用例命名为 XXXXXXXtest.php 否则,phpunit 将找不到它。

tests/
   Controller/
      ArticleController_WebTest.php
      MenuController_WebTest.php
      SecurityController_WebTest.php
      ...
   Repository/
      ArticleRepository_KernelTest.php
      ...
   Services/
      Service_UnitTest.php
      ...
   Utils/
       Util_UnitTest.php
       ...

这就是为什么我无法通过 运行 \vendor\bin\phpunit

执行所有测试的原因