本文整理汇总了PHP中Oro\Bundle\EntityConfigBundle\Provider\ConfigProvider::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigProvider::expects方法的具体用法?PHP ConfigProvider::expects怎么用?PHP ConfigProvider::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Oro\Bundle\EntityConfigBundle\Provider\ConfigProvider
的用法示例。
在下文中一共展示了ConfigProvider::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetFields
/**
* @param array $fields
* @param array $configValues
* @param array $expected
*
* @dataProvider fieldsDataProvider
*/
public function testGetFields(array $fields, array $configValues, array $expected)
{
$entity = new \StdClass();
foreach ($fields as $field) {
/** @var ConfigInterface $field */
$fieldId = $field->getId();
/** @var FieldConfigId $fieldId */
$fieldName = $fieldId->getFieldName();
$entity->{$fieldName} = $fieldName;
}
$this->configProvider->expects($this->once())->method('filter')->will($this->returnValue($fields));
$config = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
$this->configProvider->expects($this->any())->method('getConfigById')->will($this->returnValue($config));
foreach ($configValues as $key => $configValue) {
$config->expects($this->at($key))->method('get')->will($this->returnCallback(function ($value, $strict, $default) use($configValue) {
if (!is_null($configValue)) {
return $configValue;
}
return $default;
}));
}
$this->dispatcher->expects($this->exactly(sizeof($fields)))->method('dispatch');
$rows = $this->extension->getFields($entity);
$this->assertEquals(json_encode($expected), json_encode($rows));
}
示例2: prepareConfigProvider
protected function prepareConfigProvider(array $configValues, $className)
{
/** @var \PHPUnit_Framework_MockObject_MockObject|ConfigIdInterface $configId */
$configId = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\ConfigIdInterface');
$entityConfig = new Config($configId);
$entityConfig->setValues($configValues);
$this->configProvider->expects($this->once())->method('hasConfig')->with($this->equalTo($className))->will($this->returnValue(true));
$this->configProvider->expects($this->once())->method('getConfig')->with($this->equalTo($className))->will($this->returnValue($entityConfig));
}
示例3: testCreateEntityMetadataByClass
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testCreateEntityMetadataByClass()
{
$this->doctrineHelper->expects($this->once())->method('getMetadataFor')->with(self::CLASS_NAME)->will($this->returnValue($this->classMetadata));
$this->entityExtendConfigProvider->expects($this->any())->method('getConfigs')->with(static::CLASS_NAME)->will($this->returnValue([]));
$this->classMetadata->name = static::CLASS_NAME;
$this->classMetadata->expects($this->any())->method('getIdentifierFieldNames')->will($this->returnValue(['id']));
// Test creation of entity metadata
$entityMetadataCallIndex = 0;
$entityMetadata = $this->createEntityMetadata();
$metadataFactoryCallIndex = 0;
$this->metadataFactory->expects($this->at($metadataFactoryCallIndex++))->method('createEntityMetadata')->with([], $this->isType('array'))->will($this->returnValue($entityMetadata));
// Test adding doctrine fields
$doctrineFieldNames = ['id', 'foo_field', 'bar_field'];
$doctrineFieldNamesWithoutId = ['foo_field', 'bar_field'];
$idFieldNames = ['id'];
$this->classMetadata->expects($this->any())->method('getIdentifierFieldNames')->will($this->returnValue($idFieldNames));
$this->classMetadata->expects($this->any())->method('getFieldNames')->will($this->returnValue($doctrineFieldNames));
$this->classMetadata->expects($this->any())->method('getFieldMapping')->will($this->returnCallback(function ($fieldName) {
return ['fieldName' => $fieldName];
}));
foreach ($doctrineFieldNamesWithoutId as $fieldName) {
$fieldMapping = ['fieldName' => $fieldName];
$fieldMetadata = $this->createFieldMetadata();
$this->metadataFactory->expects($this->at($metadataFactoryCallIndex++))->method('createFieldMetadata')->with(['field_name' => $fieldName], $fieldMapping)->will($this->returnValue($fieldMetadata));
$entityMetadata->expects($this->at($entityMetadataCallIndex++))->method('addFieldMetadata')->with($fieldMetadata);
}
// Test adding doctrine associations
$associationMappings = ['foo_association' => ['foo' => 'bar'], 'bar_association' => ['bar' => 'baz']];
$this->classMetadata->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array_keys($associationMappings)));
$this->classMetadata->expects($this->any())->method('getAssociationMapping')->will($this->returnCallback(function ($association) use($associationMappings) {
return $associationMappings[$association];
}));
foreach ($associationMappings as $fieldName => $associationMapping) {
$fieldMetadata = $this->createFieldMetadata();
$this->metadataFactory->expects($this->at($metadataFactoryCallIndex++))->method('createFieldMetadata')->with(['field_name' => $fieldName], $associationMapping)->will($this->returnValue($fieldMetadata));
$entityMetadata->expects($this->at($entityMetadataCallIndex++))->method('addFieldMetadata')->with($fieldMetadata);
}
// Test adding doctrine inverse associations
$allMetadata = [self::CLASS_NAME => $this->classMetadata, 'Namespace\\FooEntity' => $fooClassMetadata = $this->createClassMetadata(), 'Namespace\\BarEntity' => $barClassMetadata = $this->createClassMetadata(), 'Namespace\\FooBarEntity' => $fooBarClassMetadata = $this->createClassMetadata()];
$expectedClassesData = ['Namespace\\FooEntity' => ['associationMappings' => ['foo_association' => ['foo' => 'bar', 'type' => ClassMetadataInfo::ONE_TO_MANY]], 'expectedFields' => ['foo_association' => ['field_name' => 'Namespace_FooEntity_foo_association', 'merge_modes' => [MergeModes::UNITE], 'source_field_name' => 'foo_association', 'source_class_name' => 'Namespace\\FooEntity']]], 'Namespace\\BarEntity' => ['associationMappings' => ['bar_association' => ['bar' => 'baz', 'type' => ClassMetadataInfo::ONE_TO_MANY], 'skipped_many_to_many' => ['type' => ClassMetadataInfo::MANY_TO_MANY], 'skipped_mapped_by' => ['mappedBy' => self::CLASS_NAME]], 'expectedFields' => ['bar_association' => ['field_name' => 'Namespace_BarEntity_bar_association', 'merge_modes' => [MergeModes::UNITE], 'source_field_name' => 'bar_association', 'source_class_name' => 'Namespace\\BarEntity']]], 'Namespace\\FooBarEntity' => ['associationMappings' => ['bar_association' => ['bar' => 'baz', 'type' => ClassMetadataInfo::ONE_TO_ONE]], 'expectedFields' => ['bar_association' => ['field_name' => 'Namespace_FooBarEntity_bar_association', 'merge_modes' => [MergeModes::REPLACE], 'source_field_name' => 'bar_association', 'source_class_name' => 'Namespace\\FooBarEntity']]]];
$this->doctrineHelper->expects($this->once())->method('getAllMetadata')->will($this->returnValue(array_values($allMetadata)));
foreach ($expectedClassesData as $className => $expectedData) {
$metadata = $allMetadata[$className];
$metadata->expects($this->once())->method('getName')->will($this->returnValue($className));
$metadata->expects($this->once())->method('getAssociationsByTargetClass')->with(self::CLASS_NAME)->will($this->returnValue($expectedData['associationMappings']));
foreach ($expectedData['expectedFields'] as $fieldName => $expectedOptions) {
$expectedAssociationMapping = $expectedData['associationMappings'][$fieldName];
$expectedAssociationMapping['mappedBySourceEntity'] = false;
$fieldMetadata = $this->createFieldMetadata();
$this->metadataFactory->expects($this->at($metadataFactoryCallIndex++))->method('createFieldMetadata')->with($expectedOptions, $expectedAssociationMapping)->will($this->returnValue($fieldMetadata));
$entityMetadata->expects($this->at($entityMetadataCallIndex++))->method('addFieldMetadata')->with($fieldMetadata);
}
}
// Test event dispatcher
$this->eventDispatcher->expects($this->once())->method('dispatch')->with(MergeEvents::BUILD_METADATA, new EntityMetadataEvent($entityMetadata));
$this->assertEquals($entityMetadata, $this->metadataBuilder->createEntityMetadataByClass(self::CLASS_NAME));
}
示例4: testIsNoteAssociationEnabled
public function testIsNoteAssociationEnabled()
{
$config = new Config(new EntityConfigId('note', static::TEST_ENTITY_REFERENCE));
$config->set('enabled', true);
$this->noteConfigProvider->expects($this->once())->method('hasConfig')->with(static::TEST_ENTITY_REFERENCE)->will($this->returnValue(true));
$this->noteConfigProvider->expects($this->once())->method('getConfig')->with(static::TEST_ENTITY_REFERENCE)->will($this->returnValue($config));
$this->entityConfigProvider->expects($this->once())->method('hasConfig')->with(Note::ENTITY_NAME, ExtendHelper::buildAssociationName(static::TEST_ENTITY_REFERENCE))->will($this->returnValue(true));
$this->assertTrue($this->filter->isNoteAssociationEnabled(new TestEntity(1)));
}
示例5: testWithoutOwnerType
public function testWithoutOwnerType()
{
$entity = new BusinessUnit();
$className = 'Oro\\Bundle\\OrganizationBundle\\Entity\\BusinessUnit';
/** @var \PHPUnit_Framework_MockObject_MockObject|ConfigIdInterface $configId */
$configId = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\ConfigIdInterface');
$config = new Config($configId);
$config->setValues(['another_owner_type' => 'test_type']);
$this->configProvider->expects($this->once())->method('hasConfig')->with($this->equalTo($className))->will($this->returnValue(true));
$this->configProvider->expects($this->once())->method('getConfig')->with($this->equalTo($className))->will($this->returnValue($config));
$this->assertNull($this->extension->getOwnerType($entity));
}
示例6: testOnBuildMetadata
public function testOnBuildMetadata()
{
$entity = Note::ENTITY_NAME;
$alias = 'oro_bundle_notebundle_entity_note';
$calls = 1;
$config = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
$this->configProvider->expects($this->any())->method('getConfig')->willReturn($config);
$config->expects($this->exactly($calls))->method('get')->willReturn('label');
$fieldMetadataOptions = ['display' => true, 'activity' => true, 'type' => $entity, 'field_name' => $alias, 'is_collection' => true, 'template' => 'OroActivityListBundle:Merge:value.html.twig', 'label' => 'Items', 'merge_modes' => [MergeModes::NOTES_UNITE, MergeModes::NOTES_REPLACE]];
$fieldMetadata = new FieldMetadata($fieldMetadataOptions);
$this->entityMetadata->expects($this->at(1))->method('addFieldMetadata')->with($this->equalTo($fieldMetadata));
$this->activityListChainProvider->expects($this->exactly($calls))->method('isApplicableTarget')->willReturn(true);
$event = new EntityMetadataEvent($this->entityMetadata);
$this->listener->onBuildMetadata($event);
}
示例7: testWarmUpCacheWithClassName
public function testWarmUpCacheWithClassName()
{
$this->configProvider->expects($this->once())->method('hasConfig')->with(self::SOME_CLASS)->willReturn(true);
$this->configProvider->expects($this->once())->method('getConfig')->with(self::SOME_CLASS)->willReturn($this->config);
$this->cache->expects($this->once())->method('fetch')->with(self::SOME_CLASS)->willReturn(false);
$this->cache->expects($this->once())->method('save')->with(self::SOME_CLASS);
$this->provider->warmUpCache(self::SOME_CLASS);
}
示例8: testOnBuildMetadata
/**
* @dataProvider getDataProvider
*/
public function testOnBuildMetadata($keys, $calls)
{
$config = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
$this->configProvider->expects($this->any())->method('getConfig')->willReturn($config);
$config->expects($this->exactly($calls))->method('get')->willReturn('label');
$i = 0;
$k = array_keys($keys);
foreach ($k as $key) {
$i++;
$fieldMetadataOptions = ['display' => true, 'activity' => true, 'type' => $key, 'field_name' => $key, 'is_collection' => true, 'template' => 'OroActivityListBundle:Merge:value.html.twig', 'label' => 'Items', 'merge_modes' => [MergeModes::ACTIVITY_UNITE, MergeModes::ACTIVITY_REPLACE]];
$fieldMetadata = new FieldMetadata($fieldMetadataOptions);
$this->entityMetadata->expects($this->at($i))->method('addFieldMetadata')->with($this->equalTo($fieldMetadata));
}
$this->activityManager->expects($this->once())->method('getActivities')->willReturn($keys);
$event = new EntityMetadataEvent($this->entityMetadata);
$this->listener->onBuildMetadata($event);
}
示例9: getConfigProvider
/**
* @return ConfigProvider|\PHPUnit_Framework_MockObject_MockObject
*/
public function getConfigProvider()
{
if (!$this->configProvider) {
$this->configProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
$config = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
$this->configProvider->expects($this->any())->method('getConfig')->will($this->returnValue($config));
}
return $this->configProvider;
}
示例10: setConfigProvider
protected function setConfigProvider($object, $hasConfig, $isEnabled)
{
$this->configProvider->expects($this->once())->method('hasConfig')->with($object)->willReturn($hasConfig);
if ($hasConfig) {
$config = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface')->getMock();
$config->expects($this->once())->method('is')->willReturn($isEnabled);
$this->configProvider->expects($this->once())->method('getConfig')->with($object)->willReturn($config);
}
}
示例11: testLinkToScope
/**
* @dataProvider getTestData
*/
public function testLinkToScope($config, $managerCalls, $attachmentCalls)
{
$attachments = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\EmailAttachment')->disableOriginalConstructor()->getMock();
$emailBody = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\EmailBody')->disableOriginalConstructor()->getMock();
$email = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\Email')->disableOriginalConstructor()->getMock();
$event = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Event\\EmailBodyAdded')->disableOriginalConstructor()->getMock();
$configInterface = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface')->disableOriginalConstructor()->getMock();
$this->securityFacade->expects($this->once())->method('getToken')->willReturn(1);
$this->securityFacade->expects($this->once())->method('isGranted')->willReturn(true);
$this->activityListProvider->expects($this->once())->method('getTargetEntities')->willReturn([new SomeEntity()]);
$configInterface->expects($this->once())->method('get')->will($this->returnValue($config));
$this->configProvider->expects($this->once())->method('getConfig')->will($this->returnValue($configInterface));
$this->emailAttachmentManager->expects($this->exactly($managerCalls))->method('linkEmailAttachmentToTargetEntity');
$emailBody->expects($this->exactly($attachmentCalls))->method('getAttachments')->will($this->returnValue([$attachments]));
$email->expects($this->exactly($attachmentCalls))->method('getEmailBody')->will($this->returnValue($emailBody));
$event->expects($this->exactly(1))->method('getEmail')->will($this->returnValue($email));
$this->listener->linkToScope($event);
}
示例12: testGetMaxAccessLevel
/**
* @dataProvider getMaxAccessLevelDataProvider
*
* @param $accessLevel
* @param $object
* @param $expectedResult
*/
public function testGetMaxAccessLevel($accessLevel, $object, $expectedResult)
{
if ($object && $accessLevel === AccessLevel::SYSTEM_LEVEL) {
$config = new Config(new EntityConfigId('ownership', 'SomeClass'));
$config->set('owner_type', 'USER')->set('owner_field_name', 'test_field')->set('owner_column_name', 'test_column');
$this->configProvider->expects($this->once())->method('hasConfig')->with('SomeClass')->willReturn(true);
$this->configProvider->expects($this->once())->method('getConfig')->with('SomeClass')->willReturn($config);
}
$this->entityClassResolver = null;
$this->cache = null;
$this->assertEquals($expectedResult, $this->provider->getMaxAccessLevel($accessLevel, $object));
}
示例13: testGetMetadata
public function testGetMetadata()
{
$activeClassName = 'Oro\\Bundle\\SegmentBundle\\Entity\\Segment';
$newClassName = 'Test\\NewEntity';
$deletedClassName = 'Test\\DeletedEntity';
$entityConfigIds = [new EntityConfigId('entity', $activeClassName), new EntityConfigId('entity', $newClassName), new EntityConfigId('entity', $deletedClassName)];
$this->entityConfigProvider->expects($this->once())->method('getIds')->will($this->returnValue($entityConfigIds));
$this->extendConfigProvider->expects($this->any())->method('getConfig')->will($this->returnValueMap([[$activeClassName, null, $this->createExtendConfig($activeClassName, ExtendScope::STATE_ACTIVE)], [$newClassName, null, $this->createExtendConfig($newClassName, ExtendScope::STATE_NEW)], [$deletedClassName, null, $this->createExtendConfig($deletedClassName, ExtendScope::STATE_DELETE)]]));
$this->prepareRepo();
$metadata = $this->filter->getMetadata();
$this->assertTrue(isset($metadata['entity_ids']));
$this->assertEquals([$activeClassName => 'id'], $metadata['entity_ids']);
}
示例14: configureConfigProvider
protected function configureConfigProvider()
{
$this->configProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
$this->configProvider->expects($this->any())->method('hasConfig')->willReturnCallback(function ($entity) {
$entityHash = spl_object_hash($entity);
return array_key_exists($entityHash, $this->entities);
});
$this->configProvider->expects($this->any())->method('getConfig')->willReturnCallback(function ($entity) {
$entityHash = spl_object_hash($entity);
if (!array_key_exists($entityHash, $this->entities)) {
throw new RuntimeException();
}
$config = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface')->disableOriginalConstructor()->getMock();
$config->expects($this->any())->method('get')->with($this->equalTo(ActivityScope::SHOW_ON_PAGE))->willReturn($this->entities[$entityHash]);
$config->expects($this->any())->method('has')->with($this->equalTo(ActivityScope::SHOW_ON_PAGE))->willReturn(array_key_exists($entityHash, $this->entities));
return $config;
});
}
示例15: prepare
/**
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
* @param array $config
*/
protected function prepare($config)
{
$metadata = [];
$fieldConfigs = [];
foreach ($config as $entityClassName => $entityData) {
$entityMetadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
$entityMetadata->expects($this->any())->method('getName')->will($this->returnValue($entityClassName));
$metadata[$entityClassName] = $entityMetadata;
$fieldNames = [];
$fieldTypes = [];
$fieldIdentifiers = [];
$configs = [];
foreach ($entityData['fields'] as $fieldName => $fieldData) {
$fieldNames[] = $fieldName;
$fieldTypes[] = [$fieldName, $fieldData['type']];
$fieldIdentifiers[] = [$fieldName, isset($fieldData['identifier']) ? $fieldData['identifier'] : false];
$configId = new FieldConfigId('extend', $entityClassName, $fieldName, $fieldData['type']);
$configs[] = new Config($configId);
}
$fieldConfigs[$entityClassName] = $configs;
$entityMetadata->expects($this->any())->method('getFieldNames')->will($this->returnValue($fieldNames));
$entityMetadata->expects($this->any())->method('hasField')->willReturnCallback(function ($name) use($fieldNames) {
return in_array($name, $fieldNames, true);
});
$entityMetadata->expects($this->any())->method('isIdentifier')->will($this->returnValueMap($fieldIdentifiers));
$relNames = [];
$mappings = [];
if (isset($entityData['relations'])) {
$relTargetClasses = [];
foreach ($entityData['relations'] as $relName => $relData) {
$type = $relData['type'];
$relTargetClass = $relData['target_class'];
if ($type === 'ref-one') {
$mappings[$relName] = $relData;
}
$fieldTypes[] = [$relName, $type];
$relNames[] = $relName;
$relTargetClasses[] = [$relName, $relTargetClass];
}
$entityMetadata->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValueMap($relTargetClasses));
$entityMetadata->expects($this->any())->method('getAssociationMappedByTargetField')->will($this->returnValue('id'));
}
$entityMetadata->expects($this->any())->method('getAssociationNames')->will($this->returnValue($relNames));
$entityMetadata->expects($this->any())->method('hasAssociation')->willReturnCallback(function ($name) use($relNames) {
return in_array($name, $relNames, true);
});
if (isset($entityData['unidirectional_relations'])) {
foreach ($entityData['unidirectional_relations'] as $relName => $relData) {
$fieldTypes[] = [$relName, $relData['type']];
$relData['fieldName'] = $relName;
$relData['isOwningSide'] = true;
$relData['inversedBy'] = null;
$relData['sourceEntity'] = $entityClassName;
unset($relData['config']);
$mappings[$relName] = $relData;
}
$entityMetadata->expects($this->any())->method('getAssociationMappings')->will($this->returnValue($mappings));
}
$entityMetadata->expects($this->any())->method('isSingleValuedAssociation')->will($this->returnCallback(function ($field) use($mappings) {
return !empty($mappings[$field]);
}));
$entityMetadata->expects($this->any())->method('getTypeOfField')->will($this->returnValueMap($fieldTypes));
}
$em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
$metadataFactory = $this->getMock('Doctrine\\ORM\\Mapping\\ClassMetadataFactory');
$em->expects($this->any())->method('getMetadataFactory')->will($this->returnValue($metadataFactory));
$metadataFactory->expects($this->any())->method('getMetadataFor')->will($this->returnCallback(function ($entityClassName) use(&$metadata) {
return $metadata[$entityClassName];
}));
$this->doctrine->expects($this->any())->method('getManagerForClass')->with($this->isType('string'))->will($this->returnValue($em));
$this->extendConfigProvider->expects($this->any())->method('getConfigs')->will($this->returnCallback(function ($className) use($fieldConfigs) {
return $fieldConfigs[$className];
}));
$this->entityConfigProvider->expects($this->any())->method('hasConfig')->will($this->returnCallback(function ($className, $fieldName) use(&$config) {
if (isset($config[$className])) {
if ($fieldName === null) {
return true;
}
if (isset($config[$className]['fields'][$fieldName]['config'])) {
return true;
}
if (isset($config[$className]['relations'][$fieldName]['config'])) {
return true;
}
if (isset($config[$className]['unidirectional_relations'][$fieldName]['config'])) {
return true;
}
}
return false;
}));
$this->entityConfigProvider->expects($this->any())->method('getConfig')->will($this->returnCallback(function ($className, $fieldName) use(&$config) {
if (isset($config[$className])) {
if ($fieldName === null) {
//.........这里部分代码省略.........