【发布时间】:2019-10-28 06:26:16
【问题描述】:
在 PHPUnit 测试中,我试图让我的 symfony 应用程序的所有类都实现了某个接口。我的应用程序代码位于命名空间App,我的测试位于Tests。
此测试用例代码仅列出一个类如果我实例化(或“使用”)它(顶部的use 语句无效):
namespace Tests\ReportPlaceholder;
use App\ReportPlaceholder\LimitModificationsPlaceholder;
use App\ReportPlaceholder\SimpleEvaluatePlaceholder;
use App\ReportPlaceholder\ReportPlaceholderInterface;
class MyTest extends KernelTestCase{
public function provider(){
new SimpleEvaluatePlaceholder(); // <-- if I comment this line, the class is *not* found
// also a usage of SimpleEvaluatePlaceholder::class suffices
return array_map(function($p) { return [$p]; },
array_filter(get_declared_classes(), function($className){
return in_array(ReportPlaceholderInterface::class, class_implements($className));}
));
}
}
provider 在这种情况下只返回SimpleEvaluatePlaceholder
我的 composer.json 是
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
phpunit.xml 内容如下:
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="config/bootstrap.php"
verbose="true"
debug="false"
stopOnFailure="true">
【问题讨论】: