本文整理汇总了PHP中Symfony\Component\Routing\RequestContext::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestContext::expects方法的具体用法?PHP RequestContext::expects怎么用?PHP RequestContext::expects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\RequestContext
的用法示例。
在下文中一共展示了RequestContext::expects方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBuildWithUserPath
/**
* Tests the breadcrumb for a user path.
*
* @covers ::build()
* @covers ::getRequestForPath()
*/
public function testBuildWithUserPath()
{
$this->context->expects($this->once())->method('getPathInfo')->will($this->returnValue('/user/1/edit'));
$this->setupStubPathProcessor();
$route_1 = new Route('/user/1');
$this->requestMatcher->expects($this->exactly(1))->method('matchRequest')->will($this->returnCallback(function (Request $request) use($route_1) {
if ($request->getPathInfo() == '/user/1') {
return array(RouteObjectInterface::ROUTE_NAME => 'user_page', RouteObjectInterface::ROUTE_OBJECT => $route_1, '_raw_variables' => new ParameterBag(array()));
}
}));
$this->setupAccessManagerToAllow();
$this->titleResolver->expects($this->once())->method('getTitle')->with($this->anything(), $route_1)->will($this->returnValue('Admin'));
$links = $this->builder->build($this->getMock('Drupal\\Core\\Routing\\RouteMatchInterface'));
$this->assertEquals(array(0 => new Link('Home', new Url('<front>')), 1 => new Link('Admin', new Url('user_page'))), $links);
}
示例2: testBuildWithUserPath
/**
* Tests the breadcrumb for a user path.
*
* @covers ::build()
* @covers ::getRequestForPath()
*/
public function testBuildWithUserPath()
{
$this->context->expects($this->once())->method('getPathInfo')->will($this->returnValue('/user/1/edit'));
$this->setupStubPathProcessor();
$route_1 = new Route('/user/1');
$this->requestMatcher->expects($this->exactly(1))->method('matchRequest')->will($this->returnCallback(function (Request $request) use($route_1) {
if ($request->getPathInfo() == '/user/1') {
return array(RouteObjectInterface::ROUTE_NAME => 'user_page', RouteObjectInterface::ROUTE_OBJECT => $route_1, '_raw_variables' => new ParameterBag(array()));
}
}));
$link_user = '<a href="/user/1">Admin</a>';
$link_front = '<a href="/">Home</a>';
$this->linkGenerator->expects($this->at(0))->method('generate')->with('Admin', 'user_page', array(), array('html' => TRUE))->will($this->returnValue($link_user));
$this->linkGenerator->expects($this->at(1))->method('generate')->with('Home', '<front>', array(), array())->will($this->returnValue($link_front));
$this->setupAccessManagerWithTrue();
$this->titleResolver->expects($this->once())->method('getTitle')->with($this->anything(), $route_1)->will($this->returnValue('Admin'));
$links = $this->builder->build($this->getMock('Drupal\\Core\\Routing\\RouteMatchInterface'));
$this->assertEquals(array(0 => '<a href="/">Home</a>', 1 => $link_user), $links);
}
示例3: 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());
}