本文整理汇总了PHP中Symfony\Component\Routing\Generator\UrlGeneratorInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP UrlGeneratorInterface::expects方法的具体用法?PHP UrlGeneratorInterface::expects怎么用?PHP UrlGeneratorInterface::expects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Generator\UrlGeneratorInterface
的用法示例。
在下文中一共展示了UrlGeneratorInterface::expects方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetFailedMessage
public function testGetFailedMessage()
{
$message = 'test message';
$this->router->expects($this->never())->method($this->anything());
$this->translator->expects($this->once())->method('trans')->willReturn($message);
$this->assertEquals($message, $this->generator->getFailedMessage());
}
示例2: setUp
protected function setUp()
{
$this->urlGenerator = $this->getMock('Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface');
$this->security = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
$this->session = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\Session\\Session')->disableOriginalConstructor()->getMock();
$this->urlGenerator->expects($this->once())->method('generate')->with('payment_page')->willReturn('/buy/new/ticket');
$this->sut = new AccessDeniedListener($this->security, $this->urlGenerator, 'payment_page');
}
示例3: testRender
public function testRender()
{
$this->urlGenerator->expects($this->once())->method('generate')->with($this->identicalTo($route = 'route_value'), $this->identicalTo([$routeParameter = 'route_parameter' => $routeParameterValue = 'route_parameter_value']), $this->identicalTo($routeReferenceType = UrlGeneratorInterface::ABSOLUTE_PATH))->will($this->returnValue($url = 'url_value'));
$this->propertyAccessor->expects($this->once())->method('getValue')->with($this->identicalTo($data = new \stdClass()), $this->identicalTo($routeParameter))->will($this->returnValue($routeParameterValue));
$action = $this->createActionMock();
$action->expects($this->once())->method('getLabel')->will($this->returnValue($actionLabel = 'action_label'));
$action->expects($this->once())->method('getOption')->with($this->identicalTo('trans_domain'))->will($this->returnValue($actionTransDomain = 'action_trans_domain'));
$this->formFactory->expects($this->once())->method('create')->with($this->identicalTo(CsrfProtectionType::class), $this->isNull(), $this->identicalTo(['method' => $method = Request::METHOD_DELETE, 'action' => $url, 'label' => $actionLabel, 'translation_domain' => $actionTransDomain]))->will($this->returnValue($form = $this->createFormMock()));
$form->expects($this->once())->method('createView')->will($this->returnValue($view = $this->createFormViewMock()));
$this->assertSame($view, $this->type->render($data, ['action' => $action, 'method' => strtolower($method), 'route' => $route, 'route_parameters' => [$routeParameter], 'route_reference_type' => $routeReferenceType]));
}
示例4: testProcessWithRedirectRoute
public function testProcessWithRedirectRoute()
{
$data = ['data' => ['param' => 42]];
$redirectRouteName = 'redirect_route';
$redirectUrl = '/redirect/url';
$expectedResponse = new RedirectResponse($redirectUrl);
$this->router->expects($this->once())->method('generate')->with($redirectRouteName, [ProductDataStorage::STORAGE_KEY => true], UrlGeneratorInterface::ABSOLUTE_PATH)->willReturn($redirectUrl);
$this->storage->expects($this->once())->method('set')->with($data);
$this->processor->setRedirectRouteName($redirectRouteName);
$this->assertEquals($expectedResponse, $this->processor->process($data, new Request()));
}
示例5: it_redirects_to_a_destination_after_authorisation
/**
* @test
*/
public function it_redirects_to_a_destination_after_authorisation()
{
$oauthVerifier = 'verification';
// The authorisation method should get the stored request token.
$this->authService->expects($this->any())->method('getStoredRequestToken')->willReturn($this->requestToken);
// Based on the stored request token and the oauth verifier it should
// get the user from the authentication service.
$userId = 1;
$tokenCredentials = new TokenCredentials('token2', 'secret2');
$user = new User($userId, $tokenCredentials);
$this->authService->expects($this->any())->method('getAccessToken')->with($this->requestToken, $oauthVerifier)->willReturn($user);
// Afterwards it should remove the stored request token.
$this->authService->expects($this->any())->method('removeStoredRequestToken');
// Perform a fake request to the route with the query parameters.
$query = ['oauth_token' => $this->requestToken->getToken(), 'oauth_verifier' => $oauthVerifier, 'destination' => $this->destination];
$request = new Request($query);
$response = $this->controller->authorize($request);
// Make sure the response is a redirect to the destination that
// was set in the query parameters.
$this->assertEquals(new RedirectResponse($this->destination), $response);
// Make sure that the minimal user info has been stored in the session.
$this->assertEquals($this->userSessionService->getMinimalUserInfo(), $user);
// Perform the fake request again, but this time without destination
// parameter in the query.
$this->urlGenerator->expects($this->once())->method('generate')->with($this->defaultDestination)->willReturn($this->defaultDestinationUrl);
$query = ['oauth_token' => $this->requestToken->getToken(), 'oauth_verifier' => $oauthVerifier];
$request = new Request($query);
$response = $this->controller->authorize($request);
// Make sure that the response now redirects to the default
// destination.
$this->assertEquals(new RedirectResponse($this->defaultDestinationUrl), $response);
}
示例6: testSaveAndDuplicate
public function testSaveAndDuplicate()
{
$entity = $this->getProductMock();
$queryParameters = ['qwe' => 'rty'];
$this->request->query = new ParameterBag($queryParameters);
$this->request->expects($this->once())->method('getMethod')->will($this->returnValue('POST'));
$this->request->expects($this->at(1))->method('get')->with($this->anything())->will($this->returnValue(false));
$this->request->expects($this->at(2))->method('get')->with(Router::ACTION_PARAMETER)->will($this->returnValue(ProductUpdateHandler::ACTION_SAVE_AND_DUPLICATE));
$this->doctrineHelper->expects($this->once())->method('getEntityManager')->with($entity)->will($this->returnValue($this->entityManager));
$message = 'Saved';
$savedAndDuplicatedMessage = 'Saved and duplicated';
/** @var \PHPUnit_Framework_MockObject_MockObject|Form $form */
$form = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
$form->expects($this->once())->method('isValid')->will($this->returnValue(true));
$flashBag = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface')->getMock();
$flashBag->expects($this->once())->method('add')->with('success', $message);
$flashBag->expects($this->once())->method('set')->with('success', $savedAndDuplicatedMessage);
$this->session->expects($this->any())->method('getFlashBag')->will($this->returnValue($flashBag));
$saveAndStayRoute = ['route' => 'test_update'];
$saveAndCloseRoute = ['route' => 'test_view'];
$this->router->expects($this->once())->method('redirectAfterSave')->with(array_merge($saveAndStayRoute, ['parameters' => $queryParameters]), array_merge($saveAndCloseRoute, ['parameters' => $queryParameters]), $entity)->will($this->returnValue(new RedirectResponse('test_url')));
$this->translator->expects($this->once())->method('trans')->with('orob2b.product.controller.product.saved_and_duplicated.message')->will($this->returnValue($savedAndDuplicatedMessage));
$this->urlGenerator->expects($this->once())->method('generate')->with('orob2b_product_duplicate', ['id' => self::PRODUCT_ID])->will($this->returnValue('generated_redirect_url'));
$result = $this->handler->handleUpdate($entity, $form, $saveAndStayRoute, $saveAndCloseRoute, $message);
$this->assertEquals('generated_redirect_url', $result->headers->get('location'));
$this->assertEquals(302, $result->getStatusCode());
}
示例7: testRenderWithPersistent
public function testRenderWithPersistent()
{
$column = $this->createColumnMock();
$column->expects($this->once())->method('getName')->will($this->returnValue($name = 'name'));
$view = $this->createGridViewMock();
$view->expects($this->once())->method('getDefinition')->will($this->returnValue($grid = $this->createGridMock()));
$grid->expects($this->once())->method('hasSort')->with($this->identicalTo($name))->will($this->returnValue(true));
$this->requestStack->expects($this->once())->method('getMasterRequest')->will($this->returnValue($request = $this->createRequestMock()));
$request->attributes->expects($this->once())->method('get')->with($this->identicalTo('_route_params'), $this->identicalTo([]))->will($this->returnValue($routeParams = ['route' => 'param']));
$request->query->expects($this->once())->method('all')->will($this->returnValue($queryParams = ['query' => 'query']));
$grid->expects($this->once())->method('hasOption')->with($this->identicalTo('persistent'))->will($this->returnValue(true));
$grid->expects($this->exactly(2))->method('getOption')->will($this->returnValueMap([['persistent', true], ['grid_route', $route = 'route']]));
$this->filterManager->expects($this->once())->method('get')->with($this->identicalTo($grid))->will($this->returnValue([]));
$this->urlGenerator->expects($this->once())->method('generate')->with($this->identicalTo($route), $this->identicalTo(array_merge($routeParams, $queryParams, ['grid' => ['sorting' => $name]])))->will($this->returnValue($url = 'url'));
$this->assertSame($url, $this->renderer->render($view, $column, SorterInterface::ASC));
}
示例8: testActionWithValidFormAndCreatedStatusCode
public function testActionWithValidFormAndCreatedStatusCode()
{
$this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(true));
$event = $this->createActionEventMock();
$event->expects($this->once())->method('getForm')->will($this->returnValue($form = $this->createFormMock()));
$form->expects($this->once())->method('isValid')->will($this->returnValue(true));
$form->expects($this->exactly(2))->method('getData')->will($this->returnValue($data = new \stdClass()));
$this->parameterResolver->expects($this->once())->method('resolveLocationRoute')->will($this->returnValue($route = 'route'));
$this->parameterResolver->expects($this->once())->method('resolveLocationRouteParameters')->with($this->identicalTo($data))->will($this->returnValue($routeParameters = ['route_param']));
$this->urlGenerator->expects($this->once())->method('generate')->with($this->identicalTo($route), $this->identicalTo($routeParameters))->will($this->returnValue($url = 'url'));
$event->expects($this->once())->method('getStatusCode')->will($this->returnValue($statusCode = Response::HTTP_CREATED));
$event->expects($this->once())->method('setView')->with($this->callback(function (View $view) use($statusCode, $data, $url) {
$headers = $view->getHeaders();
return $view->getStatusCode() === $statusCode && $view->getData() === $data && isset($headers['location']) && $headers['location'] === [$url];
}));
$this->subscriber->onAction($event);
}
示例9: testRender
public function testRender()
{
$this->urlGenerator->expects($this->once())->method('generate')->with($this->identicalTo($route = 'route_value'), $this->identicalTo([$routeParameter = 'route_parameter' => $routeParameterValue = 'route_parameter_value']), $this->identicalTo($routeReferenceType = UrlGeneratorInterface::ABSOLUTE_PATH))->will($this->returnValue($url = 'url_value'));
$this->propertyAccessor->expects($this->once())->method('getValue')->with($this->identicalTo($data = new \stdClass()), $this->identicalTo($routeParameter))->will($this->returnValue($routeParameterValue));
$this->assertSame($url, $this->type->render($data, ['route' => $route, 'route_parameters' => [$routeParameter], 'route_reference_type' => $routeReferenceType]));
}
示例10: testGetAuthorizationUrlWithRouteName
public function testGetAuthorizationUrlWithRouteName()
{
$this->generator->expects($this->once())->method('generate')->with($routeName = 'route_name')->will($this->returnValue($redirectUrl = 'https://example.com/authorize'));
$auth = new Authorization($this->generator, $this->authUrl, $this->appId);
$this->assertEquals($this->prepareUrl($redirectUrl), $auth->getAuthorizationUrl($routeName));
}