【问题标题】:PHP unit execute all the testPHP 单元执行所有测试
【发布时间】:2020-11-21 06:11:50
【问题描述】:

我尝试运行这个命令:

php bin/phpunit

我收到此错误:

PHP 致命错误:未捕获的错误:调用未定义的方法 PHPUnit\TextUI\TestRunner::doRun() 在 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 的描述自我更新 phpunit,但什么也没做!

我实际上只能通过执行这个命令来运行我的 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

我也读过这个PHPunit Uncaught Error: Call to undefined method PHPUnit_Util_Configuration::getTestdoxGroupConfiguration() 但它并没有为我提供任何令人满意的解决方案

【问题讨论】:

  • 将您的目录 vendor 重命名为 vendorbkp 并运行 composer install 并重试。
  • 您尝试过什么调试问题?为什么你使用两个不同版本的 PHPUnit,而不是一个?
  • @NicoHaase 我尝试过的事情在我的问题中有所描述。 Composer更新,自我更新,查看我的composer.json,在网上搜索。由于我没有找到任何解决方案,我来问。而且我不知道为什么我有两个不同版本的 PHPUnit,这正是我要求它的原因
  • 遗憾的是它不起作用@Benilson,因为 vendor\bin\phpunit 已经是最新版本。

标签: composer-php phpunit symfony5


【解决方案1】:

你必须使用 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 来执行我的所有测试

【讨论】:

    猜你喜欢
    • 2019-01-04
    • 2020-05-23
    • 2015-09-10
    • 2017-01-08
    • 2015-02-20
    • 2013-07-29
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多