public function testMakeUrlUnique()
 {
     $manager = $this->registry->getManagerForClass('OroB2BRedirectBundle:Slug');
     $slug = new Slug();
     $slug->setUrl('domain.com/hvac-equipment/detection-kits');
     $slug->setRouteName('orob2b_cms_page_view');
     $slug->setRouteParameters(['id' => 1]);
     $manager->persist($slug);
     $slug1 = new Slug();
     $slug1->setUrl('domain.com/hvac-equipment/detection-kits1-1');
     $slug1->setRouteName('orob2b_cms_page_view');
     $slug1->setRouteParameters(['id' => 1]);
     $manager->persist($slug1);
     $slug2 = new Slug();
     $slug2->setUrl('domain.com/hvac-equipment/detection-kits1-2');
     $slug2->setRouteName('orob2b_cms_page_view');
     $slug2->setRouteParameters(['id' => 1]);
     $manager->persist($slug2);
     $manager->flush();
     $testSlug = new Slug();
     $testSlug->setUrl('domain.com/hvac-equipment/detection-kits');
     $testSlug->setRouteName('orob2b_cms_page_view');
     $testSlug->setRouteParameters(['id' => 2]);
     $this->slugManager->makeUrlUnique($testSlug);
     $manager->persist($testSlug);
     $manager->flush();
     $this->assertEquals('domain.com/hvac-equipment/detection-kits-1', $testSlug->getUrl());
     $testSlug1 = new Slug();
     $testSlug1->setUrl('domain.com/hvac-equipment/detection-kits');
     $testSlug1->setRouteName('orob2b_cms_page_view');
     $testSlug1->setRouteParameters(['id' => 21]);
     $this->slugManager->makeUrlUnique($testSlug1);
     $manager->persist($testSlug1);
     $manager->flush();
     $this->assertEquals('domain.com/hvac-equipment/detection-kits-2', $testSlug1->getUrl());
     $testSlug2 = new Slug();
     $testSlug2->setUrl('domain.com/hvac-equipment/detection-kits1-1');
     $testSlug2->setRouteName('orob2b_cms_page_view');
     $testSlug2->setRouteParameters(['id' => 21]);
     $this->slugManager->makeUrlUnique($testSlug2);
     $manager->persist($testSlug2);
     $manager->flush();
     $this->assertEquals('domain.com/hvac-equipment/detection-kits1-3', $testSlug2->getUrl());
 }
 /**
  * @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);
     }
 }