示例#1
0
 /**
  * dumpMap
  *
  * @param CachedCollectionInterface $routes
  * @param string $file the php file.
  *
  * @throws RuntimeException if path is invalid.
  *
  * @return void
  */
 private function dumpMap(CachedCollectionInterface $routes, $file)
 {
     // try to create dump path.
     if (!is_dir($path = dirname($file))) {
         throw new RuntimeException(sprintf('Cannot create route map "%s" at "%s". No such directory.', basename($file), $path));
     }
     file_put_contents($file, $this->dumper->dump($routes));
 }
示例#2
0
 /** @test */
 public function itShouldMatchDumpedRouteMap()
 {
     $builder = new RouteCollectionBuilder();
     $builder->any('/', 'indexAction', ['route' => 'index']);
     $builder->get('/user', 'userIndexAction', ['route' => 'user.index']);
     $builder->get('/user/{id}', 'userShowAction', ['route' => 'user.show']);
     $builder->delete('/user/{area}/{id}', 'userDeleteAction', ['route' => 'user.delete']);
     $builder->get('/front', 'frontAction', ['route' => 'frontindex']);
     $builder->get('/login', 'loginIndexAction', ['route' => 'login.index']);
     $builder->post('/login', 'loginAction', ['route' => 'login.create']);
     $matcher = new FastMatcher($loader = $this->mockLoader());
     $routes = new Routes($builder->getCollection());
     $loader->method('load')->with($routes)->willReturnCallback(function ($routes) {
         $d = new Dumper();
         return eval('?>' . $d->dump($routes));
     });
     $request = new Request('/foo/bar', 'GET');
     $match = $matcher->matchRequest($request, $routes);
     $this->assertFalse($match->isMatch());
     $request = new Request('/', 'GET');
     $match = $matcher->matchRequest($request, $routes);
     $this->assertTrue($match->isMatch(), '/ GET');
     $this->assertEquals('indexAction', $match->getHandler());
     $request = new Request('/front', 'GET');
     $match = $matcher->matchRequest($request, $routes);
     $this->assertTrue($match->isMatch(), '/front GET');
     $this->assertEquals('frontAction', $match->getHandler());
     $request = new Request('/user/backstage/12', 'DELETE');
     $match = $matcher->matchRequest($request, $routes);
     $this->assertTrue($match->isMatch(), '/user/backstage/12 DELETE');
     $this->assertEquals('userDeleteAction', $match->getHandler());
     $request = new Request('/user/backstage/12', 'GET');
     $match = $matcher->matchRequest($request, $routes);
     $this->assertFalse($match->isMatch(), '/user/backstage/12 GET');
 }
示例#3
0
 /** @test */
 public function itShouldDumpAMapAsString()
 {
     $d = new Dumper();
     $routes = $this->mockRoutes();
     $routes->method('all')->willReturn([]);
     $res = $d->dump($routes);
     $time = time();
     $this->assertEquals("<?php\n\nreturn array (\n  'prefix' => 'r{$time}',\n);", $res);
 }