public function testWithUrlMap()
 {
     $fooFactoryCalled = 0;
     $barFactoryCalled = 0;
     $foo = new LazyHttpKernel(function () use(&$fooFactoryCalled) {
         $fooFactoryCalled++;
         return $this->createKernel('foo');
     });
     $bar = new LazyHttpKernel(function () use(&$barFactoryCalled) {
         $barFactoryCalled++;
         return $this->createKernel('bar');
     });
     $app = $this->createHelloKernel();
     $kernel = new UrlMap($app, ['/foo' => $foo, '/bar' => $bar]);
     $request = Request::create('/foo');
     $response = $kernel->handle($request);
     $this->assertSame(1, $fooFactoryCalled);
     $this->assertSame(0, $barFactoryCalled);
 }
示例#2
0
 public function testShouldBeStackable()
 {
     $app = new CallableHttpKernel(function (Request $request) {
         return new Response("Fallback!");
     });
     // $this do not reference the wrapping object in 5.3
     $self = $this;
     $urlMapInner = new UrlMap($app);
     $urlMapInner->setMap(array('/bar' => new CallableHttpKernel(function (Request $request) use($self) {
         $self->assertEquals('/', $request->getPathinfo());
         $self->assertEquals('/foo/bar', $request->attributes->get(UrlMap::ATTR_PREFIX));
         $self->assertEquals('/foo/bar', $request->getBaseUrl());
         return new Response("Hello World");
     })));
     $urlMapOuter = new UrlMap($app);
     $urlMapOuter->setMap(array('/foo' => $urlMapInner));
     $response = $urlMapOuter->handle($request = Request::create('/foo/bar?baz=fiz'));
     $urlMapOuter->terminate($request, $response);
     $this->assertEquals('Hello World', $response->getContent());
 }