本文整理汇总了PHP中Symfony\Component\Routing\Matcher\UrlMatcherInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP UrlMatcherInterface::expects方法的具体用法?PHP UrlMatcherInterface::expects怎么用?PHP UrlMatcherInterface::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Matcher\UrlMatcherInterface
的用法示例。
在下文中一共展示了UrlMatcherInterface::expects方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->configFactory = $this->getConfigFactoryStub(['system.site' => ['page.403' => '/access-denied-page', 'page.404' => '/not-found-page']]);
$this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
$this->logger = $this->getMock('Psr\\Log\\LoggerInterface');
$this->redirectDestination = $this->getMock('\\Drupal\\Core\\Routing\\RedirectDestinationInterface');
$this->redirectDestination->expects($this->any())->method('getAsArray')->willReturn(['destination' => 'test']);
$this->accessUnawareRouter = $this->getMock('Symfony\\Component\\Routing\\Matcher\\UrlMatcherInterface');
$this->accessUnawareRouter->expects($this->any())->method('match')->willReturn(['_controller' => 'mocked']);
$this->customPageSubscriber = new CustomPageExceptionHtmlSubscriber($this->configFactory, $this->kernel, $this->logger, $this->redirectDestination, $this->accessUnawareRouter);
// You can't create an exception in PHP without throwing it. Store the
// current error_log, and disable it temporarily.
$this->errorLog = ini_set('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
}
示例2: testIsValidWithNotExistingPath
/**
* Tests the isValid() method with a not existing path.
*
* @covers ::isValid
*/
public function testIsValidWithNotExistingPath()
{
$this->account->expects($this->once())->method('hasPermission')->with('link to any page')->willReturn(FALSE);
$this->accessUnawareRouter->expects($this->never())->method('match');
$this->accessAwareRouter->expects($this->once())->method('match')->with('/not-existing-path')->willThrowException(new ResourceNotFoundException());
$this->pathProcessor->expects($this->once())->method('processInbound')->willReturnArgument(0);
$this->assertFalse($this->pathValidator->isValid('not-existing-path'));
}
示例3: testGetUrlIfValidWithoutAccessCheck
/**
* Tests the getUrlIfValidWithoutAccessCheck() method.
*
* @covers ::getUrlIfValidWithoutAccessCheck
*/
public function testGetUrlIfValidWithoutAccessCheck()
{
$this->account->expects($this->never())->method('hasPermission')->with('link to any page');
$this->accessAwareRouter->expects($this->never())->method('match');
$this->accessUnawareRouter->expects($this->once())->method('match')->with('/test-path')->willReturn([RouteObjectInterface::ROUTE_NAME => 'test_route', '_raw_variables' => new ParameterBag(['key' => 'value'])]);
$this->pathProcessor->expects($this->once())->method('processInbound')->willReturnArgument(0);
$url = $this->pathValidator->getUrlIfValidWithoutAccessCheck('test-path');
$this->assertInstanceOf('Drupal\\Core\\Url', $url);
$this->assertEquals('test_route', $url->getRouteName());
$this->assertEquals(['key' => 'value'], $url->getRouteParameters());
}
示例4: testProducedLinks
/**
* @param string $method
* @dataProvider getLinkMethods
*/
public function testProducedLinks($method)
{
$listener = $this->getListener();
$event = $this->getEvent();
$urlParams = ['foo' => 'bar'];
$this->urlMatcher->expects($this->exactly(3))->method('match')->willReturn($urlParams);
$event->getRequest()->setMethod($method);
$event->getRequest()->headers->set('Link', 'link1,link2, link3');
$this->context->method('getMethod')->willReturn('METHOD');
$this->context->expects($this->exactly(2))->method('setMethod')->withConsecutive(['GET'], ['METHOD']);
$listener->onKernelRequest($event);
$this->assertTrue($event->getRequest()->attributes->has('links'));
/** @var LinkHeader[] $links */
$links = $event->getRequest()->attributes->get('links');
$this->assertEquals(3, count($links));
$this->assertEquals('link1', $links[0]->getOriginalHeader());
$this->assertEquals($urlParams, $links[0]->getUrlParameters());
$this->assertEquals('link2', $links[1]->getOriginalHeader());
$this->assertEquals('link3', $links[2]->getOriginalHeader());
}
示例5: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->configFactory = $this->getConfigFactoryStub(['system.site' => ['page.403' => '/access-denied-page', 'page.404' => '/not-found-page']]);
$this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
$this->logger = $this->getMock('Psr\\Log\\LoggerInterface');
$this->redirectDestination = $this->getMock('\\Drupal\\Core\\Routing\\RedirectDestinationInterface');
$this->redirectDestination->expects($this->any())->method('getAsArray')->willReturn(['destination' => 'test']);
$this->accessUnawareRouter = $this->getMock('Symfony\\Component\\Routing\\Matcher\\UrlMatcherInterface');
$this->accessUnawareRouter->expects($this->any())->method('match')->willReturn(['_controller' => 'mocked']);
$this->accessManager = $this->getMock('Drupal\\Core\\Access\\AccessManagerInterface');
$this->accessManager->expects($this->any())->method('checkNamedRoute')->willReturn(AccessResult::allowed()->addCacheTags(['foo', 'bar']));
$this->customPageSubscriber = new CustomPageExceptionHtmlSubscriber($this->configFactory, $this->kernel, $this->logger, $this->redirectDestination, $this->accessUnawareRouter, $this->accessManager);
$path_validator = $this->getMock('Drupal\\Core\\Path\\PathValidatorInterface');
$path_validator->expects($this->any())->method('getUrlIfValidWithoutAccessCheck')->willReturn(Url::fromRoute('foo', ['foo' => 'bar']));
$container = new ContainerBuilder();
$container->set('path.validator', $path_validator);
\Drupal::setContainer($container);
// You can't create an exception in PHP without throwing it. Store the
// current error_log, and disable it temporarily.
$this->errorLog = ini_set('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
}
示例6: testHandleWithGetRequest
/**
* Tests onHandleException with a GET request.
*/
public function testHandleWithGetRequest()
{
$request = Request::create('/test', 'GET', array('name' => 'druplicon', 'pass' => '12345'));
$request->attributes->set(AccessAwareRouterInterface::ACCESS_RESULT, AccessResult::forbidden()->addCacheTags(['druplicon']));
$request_context = new RequestContext();
$request_context->fromRequest($request);
$this->accessUnawareRouter->expects($this->any())->method('getContext')->willReturn($request_context);
$this->kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
return new Response($request->getMethod() . ' ' . UrlHelper::buildQuery($request->query->all()));
}));
$event = new GetResponseForExceptionEvent($this->kernel, $request, 'foo', new NotFoundHttpException('foo'));
$this->customPageSubscriber->onException($event);
$response = $event->getResponse();
$result = $response->getContent() . " " . UrlHelper::buildQuery($request->request->all());
$this->assertEquals('GET name=druplicon&pass=12345&destination=test&_exception_statuscode=404 ', $result);
$this->assertEquals(AccessResult::forbidden()->addCacheTags(['druplicon', 'foo', 'bar']), $request->attributes->get(AccessAwareRouterInterface::ACCESS_RESULT));
}