public function test()
 {
     $coll = new RouteCollection();
     $coll->add('foo', new Route('/foo', array(), array(), array(), '', array(), array('POST')));
     $coll->add('bar', new Route('/bar/{id}', array(), array('id' => '\\d+')));
     $coll->add('bar1', new Route('/bar/{name}', array(), array('id' => '\\w+'), array(), '', array(), array('POST')));
     $coll->add('bar2', new Route('/foo', array(), array(), array(), 'baz'));
     $coll->add('bar3', new Route('/foo1', array(), array(), array(), 'baz'));
     $coll->add('bar4', new Route('/foo2', array(), array(), array(), 'baz', array(), array(), 'context.getMethod() == "GET"'));
     $context = new RequestContext();
     $context->setHost('baz');
     $matcher = new TraceableUrlMatcher($coll, $context);
     $traces = $matcher->getTraces('/babar');
     $this->assertSame(array(0, 0, 0, 0, 0, 0), $this->getLevels($traces));
     $traces = $matcher->getTraces('/foo');
     $this->assertSame(array(1, 0, 0, 2), $this->getLevels($traces));
     $traces = $matcher->getTraces('/bar/12');
     $this->assertSame(array(0, 2), $this->getLevels($traces));
     $traces = $matcher->getTraces('/bar/dd');
     $this->assertSame(array(0, 1, 1, 0, 0, 0), $this->getLevels($traces));
     $traces = $matcher->getTraces('/foo1');
     $this->assertSame(array(0, 0, 0, 0, 2), $this->getLevels($traces));
     $context->setMethod('POST');
     $traces = $matcher->getTraces('/foo');
     $this->assertSame(array(2), $this->getLevels($traces));
     $traces = $matcher->getTraces('/bar/dd');
     $this->assertSame(array(0, 1, 2), $this->getLevels($traces));
     $traces = $matcher->getTraces('/foo2');
     $this->assertSame(array(0, 0, 0, 0, 0, 1), $this->getLevels($traces));
 }
    public function test()
    {
        $coll = new RouteCollection();
        $coll->add('foo', new Route('/foo', array(), array('_method' => 'POST')));
        $coll->add('bar', new Route('/bar/{id}', array(), array('id' => '\d+')));
        $coll->add('bar1', new Route('/bar/{name}', array(), array('id' => '\w+', '_method' => 'POST')));

        $context = new RequestContext();

        $matcher = new TraceableUrlMatcher($coll, $context);
        $traces = $matcher->getTraces('/babar');
        $this->assertEquals(array(0, 0, 0), $this->getLevels($traces));

        $traces = $matcher->getTraces('/foo');
        $this->assertEquals(array(1, 0, 0), $this->getLevels($traces));

        $traces = $matcher->getTraces('/bar/12');
        $this->assertEquals(array(0, 2), $this->getLevels($traces));

        $traces = $matcher->getTraces('/bar/dd');
        $this->assertEquals(array(0, 1, 1), $this->getLevels($traces));

        $context->setMethod('POST');
        $traces = $matcher->getTraces('/foo');
        $this->assertEquals(array(2), $this->getLevels($traces));

        $traces = $matcher->getTraces('/bar/dd');
        $this->assertEquals(array(0, 1, 2), $this->getLevels($traces));
    }
 /**
  * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
  */
 public function testRedirectWhenNoSlashForNonSafeMethod()
 {
     $coll = new RouteCollection();
     $coll->add('foo', new Route('/foo/'));
     $context = new RequestContext();
     $context->setMethod('POST');
     $matcher = $this->getMockForAbstractClass('Symfony\\Component\\Routing\\Matcher\\RedirectableUrlMatcher', array($coll, $context));
     $matcher->match('/foo');
 }
 public function testHttpRoutes()
 {
     $client = self::createClient();
     $router = $client->getContainer()->get('router');
     $context = new RequestContext();
     $context->setMethod('POST');
     $router->setContext($context);
     $router->match('/test/');
 }
 public function testRouting()
 {
     $client = self::createClient();
     $router = $client->getContainer()->get('router');
     $context = new RequestContext();
     $context->setMethod('POST');
     $router->setContext($context);
     $match = $router->match('/test/');
     self::assertArrayHasKey('_controller', $match);
     self::assertSame(TestController::class . '::rpcAction', $match['_controller']);
     self::assertSame('test', $match['_route']);
 }
 public function testMethod()
 {
     $requestContext = new RequestContext();
     $requestContext->setMethod('post');
     $this->assertSame('POST', $requestContext->getMethod());
 }
Exemple #7
0
 /**
  * Prepare RequestContext.
  *
  * @param \Symfony\Component\Routing\RequestContext $context Request context.
  * @return void
  */
 public function prepareContext(RequestContext &$context)
 {
     $context->setMethod($this->method);
 }