4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Routing\Tests\Matcher;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Routing\Route;
16 use Symfony\Component\Routing\RouteCollection;
17 use Symfony\Component\Routing\RequestContext;
19 class RedirectableUrlMatcherTest extends TestCase
21 public function testRedirectWhenNoSlash()
23 $coll = new RouteCollection();
24 $coll->add('foo', new Route('/foo/'));
26 $matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, new RequestContext()));
27 $matcher->expects($this->once())->method('redirect');
28 $matcher->match('/foo');
32 * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
34 public function testRedirectWhenNoSlashForNonSafeMethod()
36 $coll = new RouteCollection();
37 $coll->add('foo', new Route('/foo/'));
39 $context = new RequestContext();
40 $context->setMethod('POST');
41 $matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, $context));
42 $matcher->match('/foo');
45 public function testSchemeRedirectRedirectsToFirstScheme()
47 $coll = new RouteCollection();
48 $coll->add('foo', new Route('/foo', array(), array(), array(), '', array('FTP', 'HTTPS')));
50 $matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, new RequestContext()));
52 ->expects($this->once())
54 ->with('/foo', 'foo', 'ftp')
55 ->will($this->returnValue(array('_route' => 'foo')))
57 $matcher->match('/foo');
60 public function testNoSchemaRedirectIfOnOfMultipleSchemesMatches()
62 $coll = new RouteCollection();
63 $coll->add('foo', new Route('/foo', array(), array(), array(), '', array('https', 'http')));
65 $matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, new RequestContext()));
67 ->expects($this->never())
70 $matcher->match('/foo');