本文整理汇总了PHP中Symfony\Component\Form\FormFactory::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP FormFactory::expects方法的具体用法?PHP FormFactory::expects怎么用?PHP FormFactory::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormFactory
的用法示例。
在下文中一共展示了FormFactory::expects方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPreSetData
/**
* Test preSetData
* It should add form fields for each translations
*
* @param array $options
*
* @dataProvider preSetDataProvider
*/
public function testPreSetData(array $options)
{
$target = $this->getTargetedClass($options);
$translatableEntity = $this->getTranslatableEntityMock();
$event = $this->getEventMock($this->form, $translatableEntity, []);
$locales = $options['locales'];
$requiredLocales = $options['required_locale'];
foreach ($locales as $index => $locale) {
$this->formFactory->expects($this->at($index))->method('createNamed')->with($locale, $options['widget'], '', ['label' => $this->localeConfig['locales'][$locale]['label'], 'required' => in_array($locale, $requiredLocales), 'mapped' => false, 'auto_initialize' => false])->will($this->returnValue($field = $this->getFormMock()));
$this->form->expects($this->any())->method('add')->with($this->equalTo($field));
}
$target->preSetData($event);
}
示例2: testProcessPrivileges
public function testProcessPrivileges()
{
$request = new Request();
$request->setMethod('POST');
$role = new AccountUserRole('TEST');
$roleSecurityIdentity = new RoleSecurityIdentity($role);
$appendForm = $this->getMock('Symfony\\Component\\Form\\FormInterface');
$appendForm->expects($this->once())->method('getData')->willReturn([]);
$removeForm = $this->getMock('Symfony\\Component\\Form\\FormInterface');
$removeForm->expects($this->once())->method('getData')->willReturn([]);
$firstEntityPrivilege = $this->createPrivilege('entity', 'entity:FirstClass', 'VIEW');
$secondEntityPrivilege = $this->createPrivilege('entity', 'entity:SecondClass', 'VIEW');
$entityForm = $this->getMock('Symfony\\Component\\Form\\FormInterface');
$entityForm->expects($this->once())->method('getData')->willReturn([$firstEntityPrivilege, $secondEntityPrivilege]);
$actionPrivilege = $this->createPrivilege('action', 'action', 'random_action');
$actionForm = $this->getMock('Symfony\\Component\\Form\\FormInterface');
$actionForm->expects($this->once())->method('getData')->willReturn([$actionPrivilege]);
$form = $this->getMock('Symfony\\Component\\Form\\FormInterface');
$form->expects($this->once())->method('submit')->with($request);
$form->expects($this->once())->method('isValid')->willReturn(true);
$form->expects($this->any())->method('get')->willReturnMap([['appendUsers', $appendForm], ['removeUsers', $removeForm], ['entity', $entityForm], ['action', $actionForm]]);
$this->formFactory->expects($this->once())->method('create')->willReturn($form);
$objectManager = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
$this->managerRegistry->expects($this->any())->method('getManagerForClass')->with(get_class($role))->willReturn($objectManager);
$expectedFirstEntityPrivilege = $this->createPrivilege('entity', 'entity:FirstClass', 'VIEW');
$expectedFirstEntityPrivilege->setGroup(AccountUser::SECURITY_GROUP);
$expectedSecondEntityPrivilege = $this->createPrivilege('entity', 'entity:SecondClass', 'VIEW');
$expectedSecondEntityPrivilege->setGroup(AccountUser::SECURITY_GROUP);
$expectedActionPrivilege = $this->createPrivilege('action', 'action', 'random_action');
$expectedActionPrivilege->setGroup(AccountUser::SECURITY_GROUP);
$this->privilegeRepository->expects($this->once())->method('savePrivileges')->with($roleSecurityIdentity, new ArrayCollection([$expectedFirstEntityPrivilege, $expectedSecondEntityPrivilege, $expectedActionPrivilege]));
$this->aclManager->expects($this->any())->method('getSid')->with($role)->willReturn($roleSecurityIdentity);
$this->chainMetadataProvider->expects($this->once())->method('startProviderEmulation')->with(FrontendOwnershipMetadataProvider::ALIAS);
$this->chainMetadataProvider->expects($this->once())->method('stopProviderEmulation');
$handler = new AccountUserRoleHandler($this->formFactory, $this->privilegeConfig);
$handler->setManagerRegistry($this->managerRegistry);
$handler->setAclPrivilegeRepository($this->privilegeRepository);
$handler->setAclManager($this->aclManager);
$handler->setChainMetadataProvider($this->chainMetadataProvider);
$handler->setRequest($request);
$handler->createForm($role);
$handler->process($role);
}
示例3: testProcessValidDataWithTargetEntity
/**
* @dataProvider supportedMethods
*
* @param string $method
*/
public function testProcessValidDataWithTargetEntity($method)
{
$this->entity->setPhoneNumber('phone1');
$targetEntity = new TestTarget(123);
$targetEntity1 = new TestTarget(456);
$this->request->query->set('entityClass', get_class($targetEntity));
$this->request->query->set('entityId', $targetEntity->getId());
$this->formFactory->expects($this->once())->method('createNamed')->with('orocrm_call_form', 'orocrm_call_form', $this->entity, [])->will($this->returnValue($this->form));
$this->form->expects($this->once())->method('submit')->with($this->request);
$this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
$this->phoneProvider->expects($this->never())->method('getPhoneNumber');
$this->phoneProvider->expects($this->once())->method('getPhoneNumbers')->with($this->identicalTo($targetEntity))->will($this->returnValue([['phone1', $targetEntity], ['phone2', $targetEntity], ['phone1', $targetEntity1]]));
$this->entityRoutingHelper->expects($this->once())->method('getEntity')->with(get_class($targetEntity), $targetEntity->getId())->will($this->returnValue($targetEntity));
// phone1, $targetEntity
$this->callActivityManager->expects($this->at(0))->method('addAssociation')->with($this->identicalTo($this->entity), $this->identicalTo($targetEntity));
// phone2, $targetEntity
$this->callActivityManager->expects($this->at(1))->method('addAssociation')->with($this->identicalTo($this->entity), $this->identicalTo($targetEntity));
// phone1, $targetEntity1
$this->callActivityManager->expects($this->at(2))->method('addAssociation')->with($this->identicalTo($this->entity), $this->identicalTo($targetEntity1));
$this->manager->expects($this->once())->method('persist')->with($this->entity);
$this->manager->expects($this->once())->method('flush');
$this->request->setMethod($method);
$this->assertTrue($this->handler->process($this->entity));
}