public function testOnDispatch() { // Create MvcEvent $e = new MvcEvent(); $e->setViewModel(new ViewModel()); $rm = new RouteMatch([]); $rm->setParam('controller', 'Application\\Controller\\Download'); $e->setRouteMatch($rm); $e->setTarget(new DownloadController([])); // Create EntityManager and EntityRepository $moduleDetail = new ModuleList(); $moduleDetail->setModuleDesc('Pretty description'); $repo = $this->prophesize('Doctrine\\ORM\\EntityRepository'); $repo->findOneBy(['moduleName' => 'Application'])->willReturn($moduleDetail); $em = $this->prophesize('Doctrine\\ORM\\EntityManager'); $em->getRepository('Application\\Entity\\ModuleList')->willReturn($repo); $this->sm->setService('Doctrine\\ORM\\EntityManager', $em->reveal()); // Create ViewHelperManager $headTitle = new HeadTitle(); $vhm = new HelperPluginManager(); $vhm->setService('headTitle', $headTitle); $this->sm->setService('ViewHelperManager', $vhm); $this->module->onDispatch($e); $fbMeta = $e->getViewModel()->getVariable('fbMeta'); $this->assertEquals(sprintf('%s-Real Live Learn ZF2', $moduleDetail->getModuleDesc()), $fbMeta['title']); $this->assertEquals(sprintf('%s-', $moduleDetail->getModuleDesc()), $fbMeta['description']); }