I'm unit testing a ZF2 Controller, below is the test class:
<?php
class RestControllerTest extends AbstractHttpControllerTestCase
{
public function setUp()
{
Bootstrap::init();
$this->setApplicationConfig(Bootstrap::getConfig());
parent::setup();
}
public function testCreate()
{
$paramsArr = array(/** Params Here **/);
$this->dispatch('/transcode', 'POST', $paramsArr);
$this->assertResponseStatusCode(204);
$this->assertControllerName('Transcode\Controller\Rest');
$this->assertMatchedRouteName('transcode');
}
}
My unit test is failing, indicating a ServiceNotFoundException on logger.transcode, which is attached to the eventmanager onBootstrap of the Transcode module:
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$app = $e->getTarget();
$serviceManager = $app->getServiceManager();
$eventManager->attach($serviceManager->get('Transcode\Listener'));
}
Transcode\Listener is instantiated via a Factory:
public function createService(ServiceLocatorInterface $serviceLocator)
{
$logger = $serviceLocator->get('logger.transcode');
$service = new TranscodeListener($logger);
return $service;
}
And finally, logger.transcode is set via a config file which creates logger.transcode as an abstract factory in the EnliteMonolog module.
Any idea why the unit test can't attach the listener to workflow?
Aucun commentaire:
Enregistrer un commentaire