我尝试运行此命令:
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() 但这并不能为我提供令人满意的解决方案
答案 0 :(得分:0)
您必须使用
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