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

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

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

我想要运行的测试是:

<?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

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

The test that I want to run is:

&lt;?php
    

namespace test\ccs\repository;
    
    

use test\UnitTestCase;
    
    

class SignInRepositoryTest extends UnitTestCase
    {

   ...
   ...

}

Composer.json has:

 &quot;autoload&quot;: {
        	
       &quot;classmap&quot;: [
        		
          &quot;app/controllers&quot;,
        		
          &quot;app/models&quot;,
        		
          &quot;app/views&quot;
        	
        ],
        
       	&quot;psr-4&quot;: {
         
          &quot;ccs\\&quot;: &quot;library/ccs/&quot;,
                   
          &quot;test\\&quot;: &quot;tests/test/&quot;
            
        }
     },

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:

&quot;autoload&quot;: {
...},
&quot;autoload-dev&quot;: {
    &quot;psr-4&quot;: {
        &quot;test\\&quot;: &quot;tests/test/&quot;
,
    }
},

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:

确定