英文:
Uncaught Error: Class "Test\TestCase" not found running test with PHPStorm
问题
我正在使用 PHPUNIT 9.5,并且像下面的图片所示在 PHPStorm 中运行测试:
我想要运行的测试是:
<?php
namespace test\ccs\repository;
use test\UnitTestCase;
class SignInRepositoryTest extends UnitTestCase
{
// ...
// ...
}
Composer.json 文件包含:
"autoload": {
"classmap": [
"app/controllers",
"app/models",
"app/views"
],
"psr-4": {
"ccs\\": "library/ccs/",
"test\\": "tests/test/"
}
}
当我运行测试时,我收到以下错误信息:
PHP 致命错误:未找到类 "test\UnitTestCase"
位置在
C:\inetpub\PublicPortal\application\ccsignin\tests\test\ccs\repository\SignInRepositoryTest.php:4
堆栈跟踪:
#0 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\Util\FileLoader.php(66):
include_once()
#1 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\Util\FileLoader.php(49):
PHPUnit\Util\FileLoader::load()
#2 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\Framework\TestSuite.php(397):
PHPUnit\Util\FileLoader::checkAndLoad()
#3 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\Framework\TestSuite.php(527):
PHPUnit\Framework\TestSuite->addTestFile()
#4 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\Runner\BaseTestRunner.php(98):
PHPUnit\Framework\TestSuite->addTestFiles()
#5 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\TextUI\Command.php(121):
PHPUnit\Runner\BaseTestRunner->getTest()
#6 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\TextUI\Command.php(97):
PHPUnit\TextUI\Command->run()
#7 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\phpunit(98):PHPUnit\TextUI\Command::main()
#8 {main}接下来出现 PHPUnit\TextUI\RuntimeException 错误:未找到类 "test\UnitTestCase"
位置在
C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\TextUI\Command.php:99
堆栈跟踪:
#0 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\phpunit(98):PHPUnit\TextUI\Command::main()
#1 {main} 抛出于 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\TextUI\Command.php
的第 99 行
英文:
I'm using PHPUNIT 9.5 and I'm running tests with PHPStorm like I show in the following image
The test that I want to run is:
<?php
namespace test\ccs\repository;
use test\UnitTestCase;
class SignInRepositoryTest extends UnitTestCase
{
...
...
}
Composer.json has:
"autoload": {
"classmap": [
"app/controllers",
"app/models",
"app/views"
],
"psr-4": {
"ccs\\": "library/ccs/",
"test\\": "tests/test/"
}
},
When I run the test I got the error:
> PHP Fatal error: Uncaught Error: Class "test\UnitTestCase" not found
> in
> C:\inetpub\PublicPortal\application\ccsignin\tests\test\ccs\repository\SignInRepositoryTest.php:4
> Stack trace:
> #0 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\Util\FileLoader.php(66):
> include_once()
> #1 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\Util\FileLoader.php(49):
> PHPUnit\Util\FileLoader::load()
> #2 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\Framework\TestSuite.php(397):
> PHPUnit\Util\FileLoader::checkAndLoad()
> #3 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\Framework\TestSuite.php(527):
> PHPUnit\Framework\TestSuite->addTestFile()
> #4 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\Runner\BaseTestRunner.php(98):
> PHPUnit\Framework\TestSuite->addTestFiles()
> #5 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\TextUI\Command.php(121):
> PHPUnit\Runner\BaseTestRunner->getTest()
> #6 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\TextUI\Command.php(97):
> PHPUnit\TextUI\Command->run()
> #7 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\phpunit(98): PHPUnit\TextUI\Command::main()
> #8 {main}
>
> Next PHPUnit\TextUI\RuntimeException: Class "test\UnitTestCase" not
> found in
> C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\TextUI\Command.php:99
> Stack trace:
> #0 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\phpunit(98): PHPUnit\TextUI\Command::main()
> #1 {main} thrown in C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\TextUI\Command.php
> on line 99
答案1
得分: 1
Typically, tests are configured in the autoload-dev:
"autoload": {...},
"autoload-dev": {
"psr-4": {
"test\\": "tests/test/",
}
},
And run
composer dumpautoload -o
Also, make sure that PhpStorm settings are correct, for example:
- Path to script:
/app/vendor/autoload.php
- Default configuration file:
/app/phpunit.xml
- Default bootstrap file:
/app/tests/bootstrap.php
英文:
Typically, tests are configured in the autoload-dev:
"autoload": {
...},
"autoload-dev": {
"psr-4": {
"test\\": "tests/test/"
,
}
},
And run
composer dumpautoload -o
Also, make sure that PhpStorm settings are correct, for example:
- Path to script:
/app/vendor/autoload.php
- Default configuration file:
/app/phpunit.xml
- Default bootstrap file:
/app/tests/bootstrap.php
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论