命名空间不适用于 Symfony 和 Composer
Namespaces not working with Symfony and Composer
我一定是漏了什么;我正在尝试 运行 一些测试,但由于命名空间的原因,类 从未被发现。
这是我的结构。
-app
-tests
-Unit
-TestInterface.php
-common
-MyTest.php
这是我的 TestInterface.php:
namespace App\Tests\Unit;
interface TestInterface
{
}
这是我的 MyTest.php:
namespace App\Tests\Unit\common;
use App\Tests\Unit\TestInterface;
class MyTest implements TestInterface
{
}
这里是composer.json的相关部分:
"autoload": {
"psr-4": {
"App\": "src/",
"spec\": "spec/"
}
},
"autoload-dev": {
"psr-4": {
"App\Tests\": "tests/"
}
},
这里是错误:
PHP Fatal error: Interface 'App\Tests\Unit\TestInterface' not found
我在这里错过了什么?
自己回答,代码没问题。
我正在从 another.phar 加载 PHPUnit。通过 composer 安装 PHPUnit:
composer require --dev phpunit/phpunit ^8
并从 ./bin 使用它并且工作正常。
我一定是漏了什么;我正在尝试 运行 一些测试,但由于命名空间的原因,类 从未被发现。
这是我的结构。
-app
-tests
-Unit
-TestInterface.php
-common
-MyTest.php
这是我的 TestInterface.php:
namespace App\Tests\Unit;
interface TestInterface
{
}
这是我的 MyTest.php:
namespace App\Tests\Unit\common;
use App\Tests\Unit\TestInterface;
class MyTest implements TestInterface
{
}
这里是composer.json的相关部分:
"autoload": {
"psr-4": {
"App\": "src/",
"spec\": "spec/"
}
},
"autoload-dev": {
"psr-4": {
"App\Tests\": "tests/"
}
},
这里是错误:
PHP Fatal error: Interface 'App\Tests\Unit\TestInterface' not found
我在这里错过了什么?
自己回答,代码没问题。
我正在从 another.phar 加载 PHPUnit。通过 composer 安装 PHPUnit:
composer require --dev phpunit/phpunit ^8
并从 ./bin 使用它并且工作正常。