/** * Tests the createFromRequest method. * * @covers ::createFromRequest() * * @expectedException \Drupal\Core\Routing\MatchingRouteNotFoundException * @expectedExceptionMessage No matching route could be found for the request: request_as_a_string */ public function testCreateFromRequest() { // Mock the request in order to override the __toString() method. $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request'); $request->expects($this->once())->method('__toString')->will($this->returnValue('request_as_a_string')); $this->router->expects($this->once())->method('matchRequest')->with($request)->will($this->throwException(new ResourceNotFoundException())); $this->assertNull(Url::createFromRequest($request)); }
/** * Tests that an invalid request will thrown an exception. * * @covers ::createFromRequest * * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException */ public function testUrlFromRequestInvalid() { $request = Request::create('/test-path'); $this->router->expects($this->once()) ->method('matchRequest') ->with($request) ->will($this->throwException(new ResourceNotFoundException())); $this->assertNull(Url::createFromRequest($request)); }