/** * @expectedException \Symfony\Component\Routing\Exception\MethodNotAllowedException */ public function testPostOnlyRequest($value = '') { $coll = new RouteCollection(); $coll->add('foo', new Route('/foo', array(), array('_method' => 'POST|HEAD'))); $context = new RequestContext('/foo', 'GET'); $matcher = new UrlMatcher($coll, $context); $result = $matcher->match('/foo'); }
/** * Check that no route matching the slug exists * * @param string $slug * @throws \InvalidArgumentException Throws exception if $slug is not a string * @throws Exception\SlugUpdateException Throws exception if route exists matching slug * @throws Exception\SlugUpdateException Rethrows exception if a ResourceNotFoundException is caught */ private function _checkRoute($slug) { if (!is_string($slug)) { throw new \InvalidArgumentException('Slug must be a string, ' . gettype($slug) . ' given'); } try { $routes = $this->_urlMatcher->match($slug); // continue if the frontend route is the most prominent if ($routes['_route'] !== 'ms.cms.frontend') { throw new Exception\SlugUpdateException('`' . $slug . '` cannot be set as it conflicts with an existing route', 'ms.cms.feedback.force-slug.failure.reserved-route'); } } catch (ResourceNotFoundException $e) { throw new Exception\SlugUpdateException($e->getMessage(), 'ms.cms.feedback.force-slug.failure.not-matched'); } }
public function testUsingPriority() { $this->_collection['first']->add('first', '/', function () { return true; }); $this->_collection['second']->add('second', '/', function () { return false; }); $matcher1 = new UrlMatcher($this->_collection->compileRoutes()->getRouteCollection(), new RequestContext()); $result = $matcher1->match('/'); $this->assertEquals($result['_route'], 'first'); $this->_collection['first']->setPriority(-900); $matcher2 = new UrlMatcher($this->_collection->compileRoutes()->getRouteCollection(), new RequestContext()); $result = $matcher2->match('/'); $this->assertEquals($result['_route'], 'second'); }