本文整理汇总了PHP中Sonata\AdminBundle\Admin\AdminInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP AdminInterface::expects方法的具体用法?PHP AdminInterface::expects怎么用?PHP AdminInterface::expects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sonata\AdminBundle\Admin\AdminInterface
的用法示例。
在下文中一共展示了AdminInterface::expects方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
$this->admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface', array('hasRoute', 'isGranted', 'generateObjectUrl', 'generateUrl', 'toString'));
$this->pool = $this->getMock('Sonata\\AdminBundle\\Admin\\Pool', array('getAdminByClass'));
$this->pool->expects($this->any())->method('getAdminByClass')->with($this->equalTo('Acme\\DemoBundle\\Model\\Demo'))->will($this->returnValue($this->admin));
$this->twigExtension = new SonataTimelineExtension($this->pool);
}
示例2: testIsGrantedWithException
public function testIsGrantedWithException()
{
$this->setExpectedException('RuntimeException', 'Something is wrong');
$this->admin->expects($this->any())->method('getCode')->will($this->returnValue('foo.bar'));
$this->securityContext->expects($this->any())->method('isGranted')->will($this->returnCallback(function (array $attributes, $object) {
throw new \RuntimeException('Something is wrong');
}));
$handler = $this->getRoleSecurityHandler(array('ROLE_BATMAN'));
$handler->isGranted($this->admin, 'BAZ');
}
示例3: testExtractWithException
public function testExtractWithException()
{
$this->setExpectedException('RuntimeException', 'Foo throws exception');
$this->fooAdmin->expects($this->any())->method('getShow')->will($this->returnCallback(function () {
throw new \RuntimeException('Foo throws exception');
}));
$catalogue = $this->adminExtractor->extract();
}
示例4: testGetUrlsafeIdentifier
public function testGetUrlsafeIdentifier()
{
$entity = new \stdClass();
// set admin to pool
$this->pool->setAdminClasses(array('stdClass' => array('sonata_admin_foo_service')));
$this->admin->expects($this->once())->method('getUrlsafeIdentifier')->with($this->equalTo($entity))->will($this->returnValue(1234567));
$this->assertEquals(1234567, $this->twigExtension->getUrlsafeIdentifier($entity));
}
示例5: setUp
public function setUp()
{
$this->showBuilder = $this->getMock('Sonata\\AdminBundle\\Builder\\ShowBuilderInterface');
$this->fieldDescriptionCollection = new FieldDescriptionCollection();
$this->admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$this->admin->expects($this->any())->method('getLabel')->will($this->returnValue('AdminLabel'));
$this->admin->expects($this->any())->method('getShowTabs')->will($this->returnValue(array()));
$this->groups = array();
$this->listShowFields = array();
// php 5.3 BC
$groups =& $this->groups;
$listShowFields =& $this->listShowFields;
$this->admin->expects($this->any())->method('getShowGroups')->will($this->returnCallback(function () use(&$groups) {
return $groups;
}));
$this->admin->expects($this->any())->method('setShowGroups')->will($this->returnCallback(function ($showGroups) use(&$groups) {
$groups = $showGroups;
}));
$this->admin->expects($this->any())->method('reorderShowGroup')->will($this->returnCallback(function ($group, $keys) use(&$groups) {
$showGroups = $groups;
$showGroups[$group]['fields'] = array_merge(array_flip($keys), $showGroups[$group]['fields']);
$groups = $showGroups;
}));
$modelManager = $this->getMock('Sonata\\AdminBundle\\Model\\ModelManagerInterface');
// php 5.3 BC
$fieldDescription = $this->getFieldDescriptionMock();
$modelManager->expects($this->any())->method('getNewFieldDescriptionInstance')->will($this->returnCallback(function ($class, $name, array $options = array()) use($fieldDescription) {
$fieldDescriptionClone = clone $fieldDescription;
$fieldDescriptionClone->setName($name);
$fieldDescriptionClone->setOptions($options);
return $fieldDescriptionClone;
}));
$this->admin->expects($this->any())->method('getModelManager')->will($this->returnValue($modelManager));
$labelTranslatorStrategy = new NoopLabelTranslatorStrategy();
$this->admin->expects($this->any())->method('getLabelTranslatorStrategy')->will($this->returnValue($labelTranslatorStrategy));
$this->admin->expects($this->any())->method('hasShowFieldDescription')->will($this->returnCallback(function ($name) use(&$listShowFields) {
if (isset($listShowFields[$name])) {
return true;
} else {
$listShowFields[$name] = true;
return false;
}
}));
$this->showBuilder->expects($this->any())->method('addField')->will($this->returnCallback(function ($list, $type, $fieldDescription, $admin) {
$list->add($fieldDescription);
}));
$this->showMapper = new ShowMapper($this->showBuilder, $this->fieldDescriptionCollection, $this->admin);
}
示例6: testGetKnpMenuWithNotGrantedList
public function testGetKnpMenuWithNotGrantedList()
{
$request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
$adminGroups = array('bar' => array('label' => 'foo', 'icon' => '<i class="fa fa-edit"></i>', 'label_catalogue' => 'SonataAdminBundle', 'items' => array(array('admin' => 'sonata_admin_foo_service', 'label' => 'fooLabel')), 'item_adds' => array(), 'roles' => array()));
$this->pool->setAdminGroups($adminGroups);
$this->admin->expects($this->once())->method('hasRoute')->with($this->equalTo('list'))->will($this->returnValue(true));
$this->admin->expects($this->any())->method('isGranted')->with($this->equalTo('LIST'))->will($this->returnValue(false));
$menu = $this->twigExtension->getKnpMenu($request);
$this->assertInstanceOf('Knp\\Menu\\ItemInterface', $menu);
$this->assertArrayNotHasKey('bar', $menu->getChildren());
$this->assertCount(0, $menu->getChildren());
}
示例7: expectTranslate
private function expectTranslate()
{
$args = func_get_args();
// creates equalTo of all arguments passed to this function
$phpunit = $this;
// PHP 5.3 compatibility
$argsCheck = array_map(function ($item) use($phpunit) {
return $phpunit->equalTo($item);
}, func_get_args());
$mock = $this->admin->expects($this->once())->method('trans');
// passes all arguments to the 'with' of the $admin->trans method
$mock = call_user_func_array(array($mock, 'with'), $argsCheck);
$mock->will($this->returnValue($args[0]));
}
示例8: testAddDuplicateNameException
public function testAddDuplicateNameException()
{
$tmpNames = array();
$this->admin->expects($this->any())->method('hasListFieldDescription')->will($this->returnCallback(function ($name) use(&$tmpNames) {
if (isset($tmpNames[$name])) {
return true;
}
$tmpNames[$name] = $name;
return false;
}));
try {
$this->listMapper->add('fooName');
$this->listMapper->add('fooName');
} catch (\RuntimeException $e) {
$this->assertContains('Duplicate field name "fooName" in list mapper. Names should be unique.', $e->getMessage());
return;
}
$this->fail('Failed asserting that exception of type "\\RuntimeException" is thrown.');
}
示例9: testRetrieveAutocompleteItemsActionNotGrantedTarget
/**
* @expectedException Symfony\Component\Security\Core\Exception\AccessDeniedException
*/
public function testRetrieveAutocompleteItemsActionNotGrantedTarget()
{
$this->admin->expects($this->once())->method('isGranted')->with('CREATE')->will($this->returnValue(true));
$entity = new Foo();
$fieldDescription = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface');
$fieldDescription->expects($this->once())->method('getType')->will($this->returnValue('sonata_type_model_autocomplete'));
$fieldDescription->expects($this->once())->method('getTargetEntity')->will($this->returnValue('Sonata\\AdminBundle\\Tests\\Fixtures\\Bundle\\Entity\\Foo'));
$fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('barField'));
$targetAdmin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$fieldDescription->expects($this->once())->method('getAssociationAdmin')->will($this->returnValue($targetAdmin));
$targetAdmin->expects($this->once())->method('isGranted')->with('LIST')->will($this->returnValue(false));
$this->admin->expects($this->once())->method('getFormFieldDescriptions')->will($this->returnValue(null));
$this->admin->expects($this->once())->method('getFormFieldDescription')->with('barField')->will($this->returnValue($fieldDescription));
$form = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
$this->admin->expects($this->once())->method('getForm')->will($this->returnValue($form));
$formType = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
$form->expects($this->once())->method('get')->with('barField')->will($this->returnValue($formType));
$formConfig = $this->getMockBuilder('Symfony\\Component\\Form\\FormConfigInterface')->disableOriginalConstructor()->getMock();
$formType->expects($this->any())->method('getConfig')->will($this->returnValue($formConfig));
$formConfig->expects($this->any())->method('getAttribute')->will($this->returnCallback(function ($name) {
switch ($name) {
case 'disabled':
return false;
case 'property':
return 'fooProperty';
case 'callback':
return;
case 'minimum_input_length':
return 3;
case 'items_per_page':
return 10;
case 'req_param_name_page_number':
return '_page';
case 'to_string_callback':
return;
}
return;
}));
$request = new Request(array('code' => 'foo.admin', 'field' => 'barField'), array(), array(), array(), array(), array('REQUEST_METHOD' => 'GET', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'));
$this->controller->retrieveAutocompleteItemsAction($request);
}
示例10: expectTranslate
private function expectTranslate($id, array $parameters = array(), $domain = null, $locale = null)
{
$this->admin->expects($this->once())->method('trans')->with($this->equalTo($id), $this->equalTo($parameters), $this->equalTo($domain), $this->equalTo($locale))->will($this->returnValue($id));
}