Uncaught Error: Class “Test\TestCase” not found running test with PHPStorm

huangapple go评论74阅读模式
英文:

Uncaught Error: Class "Test\TestCase" not found running test with PHPStorm

问题

我正在使用 PHPUNIT 9.5,并且像下面的图片所示在 PHPStorm 中运行测试:

Uncaught Error: Class “Test\TestCase” not found running test with PHPStorm

我想要运行的测试是:

  1. <?php
  2. namespace test\ccs\repository;
  3. use test\UnitTestCase;
  4. class SignInRepositoryTest extends UnitTestCase
  5. {
  6. // ...
  7. // ...
  8. }

Composer.json 文件包含:

  1. "autoload": {
  2. "classmap": [
  3. "app/controllers",
  4. "app/models",
  5. "app/views"
  6. ],
  7. "psr-4": {
  8. "ccs\\": "library/ccs/",
  9. "test\\": "tests/test/"
  10. }
  11. }

当我运行测试时,我收到以下错误信息:

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

Uncaught Error: Class “Test\TestCase” not found running test with PHPStorm

The test that I want to run is:

  1. &lt;?php

  2. namespace test\ccs\repository;
 

  3. use test\UnitTestCase;
 

  4. class SignInRepositoryTest extends UnitTestCase{
  5. ...
  6. ...
  7. }

Composer.json has:

  1. &quot;autoload&quot;: {
  2. &quot;classmap&quot;: [
  3. &quot;app/controllers&quot;,
  4. &quot;app/models&quot;,
  5. &quot;app/views&quot;
  6. ],
  7. &quot;psr-4&quot;: {
  8. &quot;ccs\\&quot;: &quot;library/ccs/&quot;,
  9. &quot;test\\&quot;: &quot;tests/test/&quot;
  10. }
  11. },

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:

  1. "autoload": {...},
  2. "autoload-dev": {
  3. "psr-4": {
  4. "test\\": "tests/test/",
  5. }
  6. },

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:

  1. &quot;autoload&quot;: {...},
  2. &quot;autoload-dev&quot;: {
  3. &quot;psr-4&quot;: {
  4. &quot;test\\&quot;: &quot;tests/test/&quot;,
  5. }
  6. },

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

huangapple
  • 本文由 发表于 2023年2月7日 04:54:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75366480.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定