本文整理汇总了PHP中Oro\Bundle\EntityBundle\ORM\DoctrineHelper::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP DoctrineHelper::expects方法的具体用法?PHP DoctrineHelper::expects怎么用?PHP DoctrineHelper::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Oro\Bundle\EntityBundle\ORM\DoctrineHelper
的用法示例。
在下文中一共展示了DoctrineHelper::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMerge
public function testMerge()
{
$account1 = new User();
$account2 = new User();
$this->setId($account1, 1);
$this->setId($account2, 2);
$entityMetadata = new EntityMetadata(['type' => ClassUtils::getRealClass($account1)]);
$entityData = new EntityData($entityMetadata, [$account1, $account2]);
$entityData->setMasterEntity($account1);
$fieldData = new FieldData($entityData, new FieldMetadata());
$fieldData->setMode(MergeModes::NOTES_REPLACE);
$fieldData->setSourceEntity($account2);
$queryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->setMethods(['getQuery', 'getResult'])->getMock();
$queryBuilder->expects($this->any())->method('getQuery')->will($this->returnSelf());
$queryBuilder->expects($this->any())->method('getResult')->will($this->returnValue([new ExtendNote()]));
$repository = $this->getMockBuilder('Oro\\Bundle\\ActivityListBundle\\Entity\\Repository\\ActivityListRepository')->disableOriginalConstructor()->setMethods(['getBaseAssociatedNotesQB', 'getActivityListQueryBuilderByActivityClass'])->getMock();
$repository->expects($this->any())->method('getBaseAssociatedNotesQB')->willReturn($queryBuilder);
$activityQueryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->setMethods(['getQuery', 'getResult'])->getMock();
$activityQueryBuilder->expects($this->any())->method('getQuery')->will($this->returnSelf());
$activityQueryBuilder->expects($this->any())->method('getResult')->will($this->returnValue([['id' => 1, 'relatedActivityId' => 11], ['id' => 3, 'relatedActivityId' => 2]]));
$repository->expects($this->any())->method('getActivityListQueryBuilderByActivityClass')->willReturn($activityQueryBuilder);
$entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->setMethods(['remove'])->getMock();
$this->doctrineHelper->expects($this->any())->method('getEntityRepository')->willReturn($repository);
$this->doctrineHelper->expects($this->any())->method('getEntityManager')->willReturn($entityManager);
$this->activityListManager->expects($this->once())->method('replaceActivityTargetWithPlainQuery');
$this->strategy->merge($fieldData);
}
示例2: testBuildFormRegularGuesser
/**
* @param bool $withRelations
*
* @dataProvider testDataProvider
*/
public function testBuildFormRegularGuesser($withRelations)
{
$entityName = 'Test\\Entity';
$this->doctrineHelperMock->expects($this->once())->method('getEntityIdentifierFieldNames')->with($entityName)->willReturn(['id']);
$fields = [['name' => 'oneField', 'type' => 'string', 'label' => 'One field'], ['name' => 'anotherField', 'type' => 'string', 'label' => 'Another field']];
if ($withRelations) {
$fields[] = ['name' => 'relField', 'relation_type' => 'ref-one', 'label' => 'Many to One field'];
}
$this->entityFieldMock->expects($this->once())->method('getFields')->willReturn($fields);
$this->formConfigMock->expects($this->at(0))->method('getConfig')->with($entityName, 'oneField')->willReturn(new Config(new FieldConfigId('form', $entityName, 'someField'), ['is_enabled' => false]));
$this->formConfigMock->expects($this->at(1))->method('getConfig')->with($entityName, 'anotherField')->willReturn(new Config(new FieldConfigId('form', $entityName, 'anotherField'), ['is_enabled' => true]));
if ($withRelations) {
$this->formConfigMock->expects($this->at(2))->method('getConfig')->with($entityName, 'relField')->willReturn(new Config(new FieldConfigId('form', $entityName, 'relField'), ['is_enabled' => true]));
$this->translatorMock->expects($this->at(0))->method('trans')->with('oro.entity.form.entity_fields')->willReturn('Fields');
$this->translatorMock->expects($this->at(1))->method('trans')->with('oro.entity.form.entity_related')->willReturn('Relations');
}
$form = $this->factory->create($this->type, null, ['entity' => $entityName, 'with_relations' => $withRelations]);
$view = $form->createView();
$this->assertEquals('update_field_choice', $view->vars['full_name'], 'Failed asserting that field name is correct');
$this->assertNotEmpty($view->vars['configs']['component']);
$this->assertEquals('entity-field-choice', $view->vars['configs']['component']);
$this->assertEquals('update_field_choice', $form->getConfig()->getType()->getName(), 'Failed asserting that correct underlying type was used');
if ($withRelations) {
$this->assertCount(2, $view->vars['choices'], 'Failed asserting that choices are grouped');
} else {
$this->assertCount(1, $view->vars['choices'], 'Failed asserting that choices exists');
/** @var ChoiceView $choice */
$choice = reset($view->vars['choices']);
$this->assertEquals('Another field', $choice->label);
}
}
示例3: testIncrementSku
/**
* @dataProvider skuDataProvider
* @param string[] $existingSku
* @param array $testCases
*/
public function testIncrementSku(array $existingSku, array $testCases)
{
$this->doctrineHelper->expects($this->any())->method('getEntityRepository')->with(self::PRODUCT_CLASS)->willReturn($this->getProductRepositoryMock($existingSku));
foreach ($testCases as $expected => $sku) {
$this->assertEquals($expected, $this->service->increment($sku));
}
}
示例4: setUp
protected function setUp()
{
$this->entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
$this->doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock();
$this->doctrineHelper->expects($this->any())->method('getEntityManager')->will($this->returnValue($this->entityManager));
$this->fieldHelper = $this->getMockBuilder('Oro\\Bundle\\ImportExportBundle\\Field\\FieldHelper')->disableOriginalConstructor()->getMock();
$this->fixer = new EntityDetachFixer($this->doctrineHelper, $this->fieldHelper, PropertyAccess::createPropertyAccessor());
}
示例5: testIsAttachmentAssociationEnabled
/**
* @param null|object $entity
* @param bool $attachmentConfigReturn
* @param bool $isNewRecord
* @param bool $isManaged
* @param bool $expected
* @dataProvider configResultProvider
*/
public function testIsAttachmentAssociationEnabled($entity, $attachmentConfigReturn, $isNewRecord, $isManaged, $expected)
{
$this->attachmentConfig->expects(is_object($entity) && !$isNewRecord ? $this->once() : $this->never())->method('isAttachmentAssociationEnabled')->with($entity)->willReturn($attachmentConfigReturn);
$this->doctrineHelper->expects(is_object($entity) && $isManaged ? $this->once() : $this->never())->method('isNewEntity')->willReturn($isNewRecord);
$this->doctrineHelper->expects(is_object($entity) ? $this->once() : $this->never())->method('isManageableEntity')->willReturn($isManaged);
$actual = $this->filter->isAttachmentAssociationEnabled($entity);
$this->assertEquals($expected, $actual);
}
示例6: testVote
/**
* @param object $object
* @param int $expected
*
* @dataProvider attributesDataProvider
*/
public function testVote($object, $expected)
{
$this->doctrineHelper->expects($this->any())->method('getEntityClass')->with($object)->will($this->returnValue(get_class($object)));
$this->voter->setClassName(get_class($object));
$this->doctrineHelper->expects($this->any())->method('getSingleEntityIdentifier')->with($object, false)->will($this->returnValue(1));
/** @var \PHPUnit_Framework_MockObject_MockObject|TokenInterface $token */
$token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
$this->assertEquals($expected, $this->voter->vote($token, $object, ['DELETE']));
}
示例7: setUp
protected function setUp()
{
$this->entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
$this->doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock();
$this->doctrineHelper->expects($this->any())->method('getEntityManager')->will($this->returnValue($this->entityManager));
$this->detachFixer = $this->getMockBuilder('Oro\\Bundle\\ImportExportBundle\\Writer\\EntityDetachFixer')->disableOriginalConstructor()->getMock();
$this->contextRegistry = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextRegistry');
$this->writer = new EntityWriter($this->doctrineHelper, $this->detachFixer, $this->contextRegistry);
}
示例8: testReverseTransform
/**
* @dataProvider transformDataProvider
*
* @param mixed $expected
* @param mixed $value
*/
public function testReverseTransform($expected, $value)
{
if (!$expected) {
$expected = new ArrayCollection();
}
$this->doctrineHelper->expects($expected->isEmpty() ? $this->never() : $this->exactly($expected->count()))->method('getEntityReference')->will($this->returnCallback(function () {
return $this->createDataObject(func_get_arg(1));
}));
$this->assertEquals($expected, $this->transformer->reverseTransform($value));
}
示例9: setUp
protected function setUp()
{
$this->formFactory = $this->getMockBuilder('Symfony\\Component\\Form\\FormFactory')->disableOriginalConstructor()->getMock();
$this->aclManager = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Acl\\Persistence\\AclManager')->disableOriginalConstructor()->getMock();
$this->privilegeRepository = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Acl\\Persistence\\AclPrivilegeRepository')->disableOriginalConstructor()->getMock();
$this->chainMetadataProvider = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Owner\\Metadata\\ChainMetadataProvider')->disableOriginalConstructor()->getMock();
$this->ownershipConfigProvider = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProviderInterface');
$this->roleRepository = $this->getMockBuilder('\\OroB2B\\Bundle\\AccountBundle\\Entity\\Repository\\AccountUserRoleRepository')->disableOriginalConstructor()->getMock();
$this->managerRegistry = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry');
$this->doctrineHelper = $this->getMockBuilder('\\Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->setConstructorArgs([$this->managerRegistry])->getMock();
$this->doctrineHelper->expects($this->any())->method('getEntityRepository')->willReturn($this->roleRepository);
}
示例10: testSubmit
/**
* @dataProvider submitProvider
*
* @param $defaultData
* @param $viewData
* @param $submittedData
* @param ArrayCollection $expected
*/
public function testSubmit($defaultData, $viewData, $submittedData, ArrayCollection $expected)
{
$this->doctrineHelper->expects($expected->isEmpty() ? $this->never() : $this->exactly($expected->count()))->method('getEntityReference')->will($this->returnCallback(function () {
return $this->createDataObject(func_get_arg(1));
}));
$form = $this->factory->create($this->type, $defaultData, ['class' => '\\stdClass']);
$this->assertEquals($viewData, $form->getViewData());
$form->submit($submittedData);
$this->assertTrue($form->isValid());
$data = $form->getData();
$this->assertEquals($expected, $data);
}
示例11: setUp
protected function setUp()
{
$this->product = new Product();
$this->sourceProduct = new Product();
$this->doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock();
$this->productPriceRepository = $this->getMockBuilder('OroB2B\\Bundle\\PricingBundle\\Entity\\Repository\\ProductPriceRepository')->disableOriginalConstructor()->getMock();
$this->objectManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
$this->doctrineHelper->expects($this->once())->method('getEntityRepository')->with($this->productPriceClass)->will($this->returnValue($this->productPriceRepository));
$this->doctrineHelper->expects($this->any())->method('getEntityManager')->with($this->productPriceClass)->will($this->returnValue($this->objectManager));
$this->listener = new ProductDuplicateListener();
$this->listener->setProductPriceClass($this->productPriceClass);
$this->listener->setDoctrineHelper($this->doctrineHelper);
}
示例12: setUp
protected function setUp()
{
$this->translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
$this->translator->expects($this->any())->method('trans')->willReturnCallback(function ($message) {
return $message . '_trans';
});
$this->doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock();
$accountGroupId = 1;
$this->repository = $this->getMockBuilder('OroB2B\\Bundle\\PaymentBundle\\Entity\\Repository\\PaymentTermRepository')->disableOriginalConstructor()->getMock();
$this->doctrineHelper->expects($this->any())->method('getEntityReference')->with('OroB2BAccountBundle:AccountGroup', $accountGroupId)->willReturn(new AccountGroup());
$this->doctrineHelper->expects($this->any())->method('getEntityRepository')->with(static::PAYMENT_TERM_CLASS)->willReturn($this->repository);
$this->extension = new AccountGroupFormExtension($this->doctrineHelper, $this->translator, static::PAYMENT_TERM_CLASS);
}
示例13: testVote
/**
* @param bool $isDefaultWebsiteRole
* @param bool $hasUsers
* @param int $expected
*
* @dataProvider attributesDataProvider
*/
public function testVote($isDefaultWebsiteRole, $hasUsers, $expected)
{
$object = new AccountUserRole();
$this->doctrineHelper->expects($this->any())->method('getEntityClass')->with($object)->will($this->returnValue(get_class($object)));
$this->voter->setClassName(get_class($object));
$this->doctrineHelper->expects($this->any())->method('getSingleEntityIdentifier')->with($object, false)->will($this->returnValue(1));
$entityRepository = $this->getMockBuilder('OroB2B\\Bundle\\CustomerBundle\\Entity\\Repository\\AccountUserRoleRepository')->disableOriginalConstructor()->getMock();
$entityRepository->expects($this->at(0))->method('isDefaultForWebsite')->will($this->returnValue($isDefaultWebsiteRole));
$entityRepository->expects($this->at(1))->method('hasAssignedUsers')->will($this->returnValue($hasUsers));
$this->doctrineHelper->expects($this->any())->method('getEntityRepository')->with('OroB2BCustomerBundle:AccountUserRole')->will($this->returnValue($entityRepository));
/** @var \PHPUnit_Framework_MockObject_MockObject|TokenInterface $token */
$token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
$this->assertEquals($expected, $this->voter->vote($token, $object, ['DELETE']));
}
示例14: testBatchUpdateException
/**
* @expectedException \RuntimeException
*
* @throws \Exception
*/
public function testBatchUpdateException()
{
/** @var MassActionInterface|\PHPUnit_Framework_MockObject_MockObject $massActionMock */
$massActionMock = $this->getMock(MassActionInterface::class);
$entityName = 'Test\\Entity';
$options = ActionConfiguration::create(['entityName' => $entityName]);
$massActionMock->expects($this->any())->method('getOptions')->will($this->returnValue($options));
/** @var IterableResultInterface|\PHPUnit_Framework_MockObject_MockObject $massActionMock */
$iteratorMock = $this->getIteratedResultMock();
$data = ['mass_edit_field' => 'name', 'name' => 'something'];
$this->doctrineHelperMock->expects($this->once())->method('getSingleEntityIdentifierFieldName')->with($entityName)->will($this->returnValue('id'));
$this->doctrineHelperMock->expects($this->once())->method('getEntityManager')->with($entityName)->will($this->returnValue($this->getEntityManagerMock(false)));
$this->actionRepo->batchUpdate($massActionMock, $iteratorMock, $data);
}
示例15: testPrepareContextTitleDataEvent
public function testPrepareContextTitleDataEvent()
{
$item = [];
$item['title'] = 'title';
$item['targetId'] = 1;
$targetClass = Email::ENTITY_CLASS;
$expectedItem = ['title' => 'new title', 'link' => 'link', 'targetId' => 1];
$entity = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\Email')->disableOriginalConstructor()->getMock();
$this->doctrineHelper->expects($this->once())->method('getEntity')->willReturn($entity);
$this->router->expects($this->once())->method('generate')->willReturn('link');
$entity->expects($this->once())->method('getSubject')->willReturn('new title');
$event = new PrepareContextTitleEvent($item, $targetClass);
$this->listener->prepareEmailContextTitleEvent($event);
$this->assertEquals($expectedItem, $event->getItem());
}