【发布时间】:2020-07-10 15:32:58
【问题描述】:
我正在创建一个独立的 Symfony 4.4 捆绑包,我需要对其进行测试!
我创建了一个扩展内核的 AppKernelTest,并注册了我所有的包:
class ServicesBundleTestingKernel extends Kernel
{
/**
* @inheritDoc
*/
public function registerBundles()
{
return [
new FrameworkBundle(),
new MonologBundle(),
new DoctrineBundle(),
new DoctrineMigrationsBundle(),
new MyServicesBundle(), // My custom bundle
];
}
/**
* @inheritDoc
*/
public function registerContainerConfiguration(LoaderInterface $loader)
{
}
}
在我的包中,我有一个需要 Doctrine Entity Manager 的服务,这是我的 service.xml(我在其中声明了我的包的所有服务)
<service id="ServicesBundle\Service\RequestHandler" class="ServicesBundle\Service\RequestHandler" public="false" >
<argument key="$logger" type="service" id="monolog.logger"/>
<argument key="$em" type="service" id="doctrine.orm.entity_manager"/>
</service>
<service id="services_request_handler" alias="ServicesBundle\Service\RequestHandler" public="true" />
我的测试课:
class DependencyTest extends WebTestCase
{
//private $container;
public function testServiceWiring()
{
self::bootKernel();
}
}
我已将我的 .env.test 配置为使用我的自定义内核类进行测试,但是当我启动测试时,我收到了这个错误:
1) ServicesBundle\Tests\DependencyTest::testServiceWiring Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:服务“services_request_handler”依赖于不存在的服务“doctrine.orm.entity_manager”。
对于下面的测试,我从 registerBundle() 方法中删除了我的 Bundle。
我尝试命令:php bin/console debug:container doctrine.orm.entity_manager,输出为:“未找到服务”
我还尝试在应用启动时查看容器中的所有学说服务,但我只有两个服务:
[0] cache.adapter.doctrine
[1] Doctrine\Common\Annotations\Reader
我不知道为什么 Doctrine Bundle 没有正确注册。
【问题讨论】:
标签: php symfony doctrine-orm doctrine symfony-4.4