当前位置: 首页>>代码示例>>PHP>>正文


PHP Router::expects方法代码示例

本文整理汇总了PHP中Symfony\Bundle\FrameworkBundle\Routing\Router::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::expects方法的具体用法?PHP Router::expects怎么用?PHP Router::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Bundle\FrameworkBundle\Routing\Router的用法示例。


在下文中一共展示了Router::expects方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testOnKernelRequest

 /**
  * @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);
     }
 }
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:49,代码来源:ForwardListenerTest.php

示例2: testOnDetectedNewFilesSendNotice

 /**
  * 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);
 }
开发者ID:anime-db,项目名称:catalog-bundle,代码行数:26,代码来源:ScanStorageTest.php


注:本文中的Symfony\Bundle\FrameworkBundle\Routing\Router::expects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。