本文整理汇总了PHP中Symfony\Component\Routing\RouterInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP RouterInterface::expects方法的具体用法?PHP RouterInterface::expects怎么用?PHP RouterInterface::expects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\RouterInterface
的用法示例。
在下文中一共展示了RouterInterface::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPath
/**
* Tests path.
*
* @param array $parameters
* @param int $page
*
* @dataProvider testPathDataProvider
*/
public function testPath(array $parameters, $page)
{
$route = 'route_name';
$this->router->expects($this->once())->method('generate')->will($this->returnValue('/'));
$result = $this->pagerExtension->path($route, $page, $parameters);
$this->assertEquals('/', $result);
}
示例2: testGetUrl
public function testGetUrl()
{
$this->router->expects($this->once())->method('generate')->with($this->equalTo('sonata_cache_opcode'), $this->equalTo(array('token' => 'token')))->will($this->returnValue('/sonata/cache/opcode/token'));
$method = new \ReflectionMethod($this->cache, 'getUrl');
$method->setAccessible(true);
$this->assertEquals('/sonata/cache/opcode/token', $method->invoke($this->cache));
}
示例3: testSingle
public function testSingle()
{
$this->channelRouter->register(new ChannelType('homepage', 'homepage', 'single'));
$this->router->expects($this->once())->method('generate')->with($this->equalTo('homepage'));
$channel = new Channel();
$channel->setType('homepage');
$this->channelRouter->getUrl($channel);
}
示例4: testFilterValueWithRedirectUriFalse
public function testFilterValueWithRedirectUriFalse()
{
$this->router->expects($this->once())->method('generate')->with('foo', array(), false)->will($this->returnValue('/test/bar'));
$this->column->setName('action');
$this->column->initOptions();
$extension = new DefaultColumnOptionsExtension();
$extension->initOptions($this->column);
$this->column->setOption('actions', array('edit' => array('route_name' => 'foo', 'absolute' => false, 'redirect_uri' => false)));
$this->assertSame(array('edit' => array('content' => 'edit', 'field_mapping_values' => array('foo' => 'bar'), 'url_attr' => array('href' => '/test/bar'))), $this->column->filterValue(array('foo' => 'bar')));
}
示例5: testCreateUserFormDataValidWillReturn201Response
public function testCreateUserFormDataValidWillReturn201Response()
{
$request = $this->createExampleRequest();
$this->formMock->expects($this->once())->method('isValid')->will($this->returnValue(true));
$this->routerMock->expects($this->once())->method('generate')->will($this->returnValue('http://example.com'));
$view = $this->controller->createUserAction($request);
$this->assertInstanceOf(User::class, $view->getData());
$this->assertSame(201, $view->getStatusCode());
$this->assertSame(['http://example.com'], $view->getHeaders()['location']);
}
示例6: testOnKernelRequestSetup
public function testOnKernelRequestSetup()
{
$this->router->expects($this->once())->method('generate')->with('ezpublishSetup')->will($this->returnValue('/setup'));
$this->router->expects($this->once())->method('getContext')->will($this->returnValue($this->getMock('Symfony\\Component\\Routing\\RequestContext')));
$event = $this->createEvent('/foo/bar');
$this->getListener('setup')->onKernelRequestSetup($event);
$this->assertTrue($event->hasResponse());
/** @var RedirectResponse $response */
$response = $event->getResponse();
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $response);
$this->assertSame('/setup', $response->getTargetUrl());
}
示例7: setUp
protected function setUp()
{
$this->router = $this->getMock('\\Symfony\\Component\\Routing\\RouterInterface');
$this->router->expects($this->any())->method('generate')->willReturnCallback(function ($route, $params) {
return serialize($params);
});
/** @var \Twig_Environment|\PHPUnit_Framework_MockObject_MockObject $twig */
$twig = $this->getMockBuilder('\\Twig_Environment')->disableOriginalConstructor()->getMock();
$twig->expects($this->any())->method('render')->willReturnCallback(function ($template, $params) {
return serialize($params);
});
$this->managerRegistry = $this->getMockBuilder('\\Symfony\\Bridge\\Doctrine\\ManagerRegistry')->disableOriginalConstructor()->getMock();
$this->extension = new DeleteMessageTextGenerator($this->router, $twig, $this->managerRegistry);
}
示例8: testRenderReplaceWithFileBrowserHandler
/**
* @dataProvider filebrowserProvider
*/
public function testRenderReplaceWithFileBrowserHandler($filebrowser)
{
$this->routerMock->expects($this->once())->method('generate')->with($this->equalTo('browse_route'), $this->equalTo(array('foo' => 'bar')), $this->equalTo(true))->will($this->returnValue('browse_url'));
$this->assertSame(sprintf('CKEDITOR.replace("foo", {"filebrowser%sUrl":"browse_url"});', $filebrowser), $this->helper->renderReplace('foo', array('filebrowser' . $filebrowser . 'Handler' => function (RouterInterface $router) {
return $router->generate('browse_route', array('foo' => 'bar'), true);
})));
}
示例9: testGenerateWithPageAliasFromHybridPage
public function testGenerateWithPageAliasFromHybridPage()
{
$page = $this->getMock('Sonata\\PageBundle\\Model\\PageInterface');
$page->expects($this->exactly(5))->method('isHybrid')->will($this->returnValue(true));
$page->expects($this->exactly(5))->method('getRouteName')->will($this->returnValue('test_route'));
$site = $this->getMock('Sonata\\PageBundle\\Model\\SiteInterface');
$this->siteSelector->expects($this->exactly(5))->method('retrieve')->will($this->returnValue($site));
$cmsManager = $this->getMock('Sonata\\PageBundle\\CmsManager\\CmsManagerInterface');
$cmsManager->expects($this->exactly(5))->method('getPageByPageAlias')->will($this->returnValue($page));
$this->cmsSelector->expects($this->exactly(5))->method('retrieve')->will($this->returnValue($cmsManager));
$this->defaultRouter->expects($this->at(0))->method('generate')->with($this->equalTo('test_route'), $this->equalTo(array('key' => 'value')), $this->equalTo(UrlGeneratorInterface::ABSOLUTE_PATH))->will($this->returnValue('/test/key/value'));
$this->defaultRouter->expects($this->at(1))->method('generate')->with($this->equalTo('test_route'), $this->equalTo(array('key' => 'value')), $this->equalTo(UrlGeneratorInterface::ABSOLUTE_PATH))->will($this->returnValue('/test/key/value'));
$this->defaultRouter->expects($this->at(2))->method('generate')->with($this->equalTo('test_route'), $this->equalTo(array('key' => 'value')), $this->equalTo(UrlGeneratorInterface::RELATIVE_PATH))->will($this->returnValue('test/key/value'));
$this->defaultRouter->expects($this->at(3))->method('generate')->with($this->equalTo('test_route'), $this->equalTo(array('key' => 'value')), $this->equalTo(UrlGeneratorInterface::ABSOLUTE_URL))->will($this->returnValue('http://localhost/test/key/value'));
$this->defaultRouter->expects($this->at(4))->method('generate')->with($this->equalTo('test_route'), $this->equalTo(array('key' => 'value')), $this->equalTo(UrlGeneratorInterface::NETWORK_PATH))->will($this->returnValue('//localhost/test/key/value'));
$url = $this->router->generate('_page_alias_homepage', array('key' => 'value'));
$this->assertEquals('/test/key/value', $url);
$url = $this->router->generate('_page_alias_homepage', array('key' => 'value'), UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals('/test/key/value', $url);
$url = $this->router->generate('_page_alias_homepage', array('key' => 'value'), UrlGeneratorInterface::RELATIVE_PATH);
$this->assertEquals('test/key/value', $url);
$url = $this->router->generate('_page_alias_homepage', array('key' => 'value'), UrlGeneratorInterface::ABSOLUTE_URL);
$this->assertEquals('http://localhost/test/key/value', $url);
$url = $this->router->generate('_page_alias_homepage', array('key' => 'value'), UrlGeneratorInterface::NETWORK_PATH);
$this->assertEquals('//localhost/test/key/value', $url);
}
示例10: setUp
protected function setUp()
{
parent::setUp();
\Locale::setDefault('en');
$this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
$this->router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
$this->requestStack = new RequestStack();
/* @var Request $request */
$request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
$this->requestStack->push($request);
$this->router->expects($this->any())->method('generate')->will($this->returnCallback(function ($param) {
return '/' . $param;
}));
$this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->addTypeExtension(new ChoiceSelect2TypeExtension($this->dispatcher, $this->requestStack, $this->router, $this->getExtensionTypeName(), 10))->getFormFactory();
$this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
$this->builder = new FormBuilder(null, null, $this->dispatcher, $this->factory);
}
示例11: getUserUrl
/**
* @test
*/
public function getUserUrl()
{
$user = new User();
$user->setId(1);
$url = '/user/view/4';
$this->router->expects($this->once())->method('generate')->with('oro_user_view', ['id' => $user->getId()])->will($this->returnValue($url));
$this->twigExtension->getUserUrl($user);
}
示例12: testExecuteException
/**
* @expectedException \Usoft\IDealBundle\Exceptions\IDealExecuteException
*
* @throws \Usoft\IDealBundle\Exceptions\IDealExecuteException
*/
public function testExecuteException()
{
$this->router->expects($this->once())->method('generate')->with('confirm_route')->willReturn('http://www.awesome-app.com/foo/bar?token=foobar');
$this->mollieAPIClient->payments = $this->payments;
$this->bank->expects($this->once())->method('getId')->willReturn(666);
$this->payments->expects($this->once())->method('create')->with(["amount" => 12.43, "description" => 'awesome test', "redirectUrl" => 'http://www.awesome-app.com/foo/bar?token=foobar', "method" => Mollie_API_Object_Method::IDEAL, "issuer" => 666])->willThrowException(new \Exception());
$this->eventDispatcher->expects($this->never())->method('dispatch');
$this->mollieDriver->execute($this->bank, 12.43, 'confirm_route');
}
示例13: testFormTypeEntityToJson
public function testFormTypeEntityToJson()
{
$entity = new Entity(1);
$className = get_class($entity);
$formData = array('auto' => '1');
$routeName = 'routename';
$this->router->expects($this->once())->method('generate')->with($routeName)->willReturn('/route/name');
$this->entityMgr->expects($this->once())->method('getReference')->with($className, 1)->willReturn($entity);
$form = $this->factory->createBuilder()->add('auto', AutocompleterType::class, array('route' => $routeName, 'class' => $className, 'method' => 'GET'))->getForm();
$view = $form->createView();
$form->submit($formData);
$data = $form['auto']->getData();
$this->assertEquals($data, $entity);
$this->assertInstanceOf($className, $data);
$this->assertArrayHasKey('auto', $view);
$this->assertArrayHasKey('attr', $view['auto']->vars);
$this->assertArrayHasKey('data-autocompleteUrl', $view['auto']->vars['attr']);
$this->assertEquals($view['auto']->vars['attr']['data-autocompleteUrl'], '/route/name');
$this->assertContains('GET', $view['auto']->vars['attr']['data-options']);
}
示例14: testGetEntitiesMetadata
public function testGetEntitiesMetadata()
{
$this->entityProvider->expects($this->at(0))->method('getEntity')->will($this->returnvalue($this->entityConfig1));
$this->entityProvider->expects($this->at(1))->method('getEntity')->will($this->returnvalue($this->entityConfig2));
$this->entityProvider->expects($this->at(2))->method('getEntity')->will($this->returnvalue($this->entityConfig3));
$extendConfigModel = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
$extendConfigModel->expects($this->any())->method('get')->with($this->equalTo('owner'))->will($this->returnValue('Custom'));
$extendProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
$extendProvider->expects($this->once())->method('map')->will($this->returnValue([]));
$extendProvider->expects($this->any())->method('getConfig')->will($this->returnValue($extendConfigModel));
$this->configManager->expects($this->any())->method('getProvider')->with($this->equalTo('extend'))->will($this->returnValue($extendProvider));
$this->configManager->expects($this->any())->method('getConfigEntityModel')->will($this->onConsecutiveCalls($this->entityConfigModel1, $this->entityConfigModel2));
$this->router->expects($this->exactly(4))->method('generate');
/** @var MetadataProvider $provider */
$provider = new MetadataProvider($this->settingsProvider, $this->entityProvider, $this->configManager, $this->router);
$result = $provider->getEntitiesMetadata();
for ($i = 1; $i < 3; $i++) {
$expectedConfig = $this->getExpectedConfig($i);
$entityName = $expectedConfig['name'];
$this->assertEquals($expectedConfig, $result[$entityName]);
}
}
示例15: testGenerateWithPageAliasFromHybridPage
public function testGenerateWithPageAliasFromHybridPage()
{
$page = $this->getMock('Sonata\\PageBundle\\Model\\PageInterface');
$page->expects($this->any())->method('isHybrid')->will($this->returnValue(true));
$page->expects($this->once())->method('getRouteName')->will($this->returnValue('test_route'));
$site = $this->getMock('Sonata\\PageBundle\\Model\\SiteInterface');
$this->siteSelector->expects($this->once())->method('retrieve')->will($this->returnValue($site));
$cmsManager = $this->getMock('Sonata\\PageBundle\\CmsManager\\CmsManagerInterface');
$cmsManager->expects($this->once())->method('getPageByPageAlias')->will($this->returnValue($page));
$this->cmsSelector->expects($this->once())->method('retrieve')->will($this->returnValue($cmsManager));
$this->defaultRouter->expects($this->once())->method('generate')->with($this->equalTo('test_route'), $this->equalTo(array('key' => 'value')), $this->equalTo(true))->will($this->returnValue('http://localhost/test/key/value'));
$url = $this->router->generate('_page_alias_homepage', array('key' => 'value'), true);
$this->assertEquals('http://localhost/test/key/value', $url);
}