I'm creating a standalone Symfony 4.4 bundle and I need to test it !
I've created an AppKernelTest which extends Kernel and I registered all my bundles :
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)
{
}
}
In my bundle, I have a service which require the Doctrine Entity Manager, here is my service.xml (where I declare all services for my bundle)
<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" />
My test class :
class DependencyTest extends WebTestCase
{
//private $container;
public function testServiceWiring()
{
self::bootKernel();
}
}
I've configured my .env.test to use my custom kernel class for the tests but when I launch the test, I got this error :
1) ServicesBundle\Tests\DependencyTest::testServiceWiring Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: The service "services_request_handler" has a dependency on a non-existent service "doctrine.orm.entity_manager".
For the tests bellow, I removed my Bundle from the registerBundle() method.
I try the command : php bin/console debug:container doctrine.orm.entity_manager
and the output is : "No service found"
I also tried to see all doctrine services in my container when the app is launched and I have only two services :
[0] cache.adapter.doctrine
[1] Doctrine\Common\Annotations\Reader
I don't know why the Doctrine Bundle is not correctly registered.