/** * @dataProvider onKernelRequestDataProvider * @param boolean $installed * @param string $requestType * @param boolean $existingController * @param array $slug_params * @param array $expected */ public function testOnKernelRequest($installed, $requestType, $existingController, array $slug_params, array $expected) { $this->listener = new ForwardListener($this->router, $this->registry, $installed); /** * @var \Symfony\Component\HttpKernel\HttpKernelInterface|\PHPUnit_Framework_MockObject_MockObject $kernel */ $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface'); $request = Request::create('http://localhost' . $slug_params['url']); if ($existingController) { $request->attributes->add(['_controller' => 'ExistingController']); } $event = new GetResponseEvent($kernel, $request, $requestType); $slug = new Slug(); $slug->setRouteName($slug_params['route_name']); $slug->setUrl($slug_params['url']); $slug->setRouteParameters($slug_params['route_parameters']); if ($requestType === HttpKernelInterface::MASTER_REQUEST) { $slugRepository = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); if ($slug_params['url'] !== '/') { $slug_params['url'] = rtrim($slug_params['url'], '/'); } if ($slug_params['url'] === '/missing-slug') { $slugRepository->expects($this->any())->method('findOneBy')->with(['url' => $slug_params['url']])->will($this->returnValue(null)); } else { $slugRepository->expects($this->any())->method('findOneBy')->with(['url' => $slug_params['url']])->will($this->returnValue($slug)); } $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $em->expects($this->any())->method('getRepository')->with('OroB2BRedirectBundle:Slug')->will($this->returnValue($slugRepository)); $this->registry->expects($this->any())->method('getManagerForClass')->with('OroB2BRedirectBundle:Slug')->will($this->returnValue($em)); $route = $this->getMockBuilder('Symfony\\Component\\Routing\\Route')->disableOriginalConstructor()->getMock(); $route->expects($this->any())->method('getDefault')->with('_controller')->will($this->returnValue('TestController')); $routeCollection = $this->getMock('Symfony\\Component\\Routing\\RouteCollection'); $routeCollection->expects($this->any())->method('get')->with('test_route')->will($this->returnValue($route)); $this->router->expects($this->any())->method('getRouteCollection')->will($this->returnValue($routeCollection)); } $this->listener->onKernelRequest($event); if ($requestType === HttpKernelInterface::MASTER_REQUEST) { $parameters = $request->attributes->all(); $this->assertEquals($expected, $parameters); } }
/** * Test on detected new files send notice. * * @dataProvider getSearchPlugins * * @param \PHPUnit_Framework_MockObject_MockObject $dafeult_plugin * @param bool $has_plugins */ public function testOnDetectedNewFilesSendNotice(\PHPUnit_Framework_MockObject_MockObject $dafeult_plugin = null, $has_plugins) { $storage = $this->getMock('\\AnimeDb\\Bundle\\CatalogBundle\\Entity\\Storage'); $event = $this->getMockBuilder('\\AnimeDb\\Bundle\\CatalogBundle\\Event\\Storage\\DetectedNewFiles')->disableOriginalConstructor()->getMock(); $event->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('bar')); $event->expects($this->once())->method('getStorage')->will($this->returnValue($storage)); $this->search->expects($this->once())->method('getDafeultPlugin')->will($this->returnValue($dafeult_plugin)); $link = null; if ($dafeult_plugin) { $dafeult_plugin->expects($this->once())->method('getLinkForSearch')->will($this->returnValue($link = 'foo'))->with('bar'); } else { $this->search->expects($this->once())->method('hasPlugins')->will($this->returnValue($has_plugins)); if ($has_plugins) { $this->router->expects($this->once())->method('generate')->will($this->returnValue($link = 'baz'))->with('fill_search_in_all', [SearchPluginForm::FORM_NAME => ['name' => 'bar']]); } } $this->testSendNotices($event, ['storage' => $storage, 'name' => 'bar', 'link' => $link], 'onDetectedNewFilesSendNotice', ScanStorage::NOTICE_TYPE_DETECTED_FILES_FOR_NEW_ITEM); }