コード例 #1
0
 protected function setUp()
 {
     $this->container = new Container();
     $this->configurationBuilder = new ConfigurationBuilder();
     $this->factory = $this->getMockBuilder('Knp\\Menu\\MenuFactory')->setMethods(array('getRouteInfo', 'processRoute'))->getMock();
     $this->factory->expects($this->any())->method('getRouteInfo')->will($this->returnValue(false));
     $this->factory->expects($this->any())->method('processRoute')->will($this->returnSelf());
 }
コード例 #2
0
 /**
  * @dataProvider hasInCacheDataProvider
  * @param boolean $hasInCache
  */
 public function testRouteCaching($hasInCache)
 {
     $params = array('id' => 20);
     $uriKey = md5('route_uri:route_name' . serialize($params));
     $aclKey = md5('route_acl:route_name');
     $cache = $this->getMockBuilder('Doctrine\\Common\\Cache\\ArrayCache')->getMock();
     $cache->expects($this->exactly(2))->method('contains')->will($this->returnValueMap(array(array($uriKey, $hasInCache), array($aclKey, $hasInCache))));
     if ($hasInCache) {
         $cache->expects($this->exactly(2))->method('fetch')->will($this->returnValueMap(array(array($uriKey, '/'), array($aclKey, 'controller::action'))));
     } else {
         $cache->expects($this->exactly(2))->method('save')->with($this->logicalOr($this->equalTo($aclKey), $this->equalTo('controller::action'), $this->equalTo($uriKey), $this->equalTo('/')));
     }
     $this->factoryExtension->setCache($cache);
     $options = array('route' => 'route_name', 'routeParameters' => $params);
     $this->assertRouteByRouteNameCalls(true, 'route_name', 'controller', 'action', (int) (!$hasInCache));
     $item = $this->factory->createItem('test', $options);
     $this->assertTrue($item->getExtra('isAllowed'));
     $this->assertInstanceOf('Knp\\Menu\\MenuItem', $item);
 }