本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadata::setIdentifier方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::setIdentifier方法的具体用法?PHP ClassMetadata::setIdentifier怎么用?PHP ClassMetadata::setIdentifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::setIdentifier方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareMocks
/**
* @return array
*/
protected function prepareMocks()
{
$configuration = new Configuration();
$configuration->addEntityNamespace('Stub', 'Oro\\Bundle\\BatchBundle\\Tests\\Unit\\ORM\\Query\\Stub');
$classMetadata = new ClassMetadata('Entity');
$classMetadata->mapField(['fieldName' => 'a', 'columnName' => 'a']);
$classMetadata->mapField(['fieldName' => 'b', 'columnName' => 'b']);
$classMetadata->setIdentifier(['a']);
$platform = $this->getMockBuilder('Doctrine\\DBAL\\Platforms\\AbstractPlatform')->setMethods([])->disableOriginalConstructor()->getMockForAbstractClass();
$statement = $this->getMockBuilder('Doctrine\\DBAL\\Statement')->setMethods(['fetch', 'fetchColumn', 'closeCursor'])->disableOriginalConstructor()->getMock();
$driverConnection = $this->getMockBuilder('Doctrine\\DBAL\\Driver\\Connection')->setMethods(['query'])->disableOriginalConstructor()->getMockForAbstractClass();
$driverConnection->expects($this->any())->method('query')->will($this->returnValue($statement));
$driver = $this->getMockBuilder('Doctrine\\DBAL\\Driver')->setMethods(['connect', 'getDatabasePlatform'])->disableOriginalConstructor()->getMockForAbstractClass();
$driver->expects($this->any())->method('connect')->will($this->returnValue($driverConnection));
$driver->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($platform));
$connection = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->setMethods(['getDatabasePlatform', 'executeQuery'])->setConstructorArgs([[], $driver])->getMock();
$connection->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($platform));
/** @var UnitOfWork $unitOfWork */
$unitOfWork = $this->getMockBuilder('UnitOfWork')->setMethods(['getEntityPersister'])->disableOriginalConstructor()->getMock();
$entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->setMethods(['getConfiguration', 'getClassMetadata', 'getConnection', 'getUnitOfWork'])->disableOriginalConstructor()->getMock();
$entityManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($configuration));
$entityManager->expects($this->any())->method('getClassMetadata')->will($this->returnValue($classMetadata));
$entityManager->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
$entityManager->expects($this->any())->method('getUnitOfWork')->will($this->returnValue($unitOfWork));
return [$entityManager, $connection, $statement];
}
示例2: prepareStubData
/**
* Prepare stub data and mocks
*
* @return array
*/
protected function prepareStubData()
{
// create product stubs
$productEntities = array();
for ($i = 1; $i <= 5; $i++) {
$indexerItem = new Item($this->entityManager, Product::getEntityName(), $i);
$entity = new Product($i);
$productEntities[$i] = $entity;
$this->productStubs[$i] = array('indexer_item' => $indexerItem, 'entity' => $entity);
}
$productMetadata = new ClassMetadata(Product::getEntityName());
$productMetadata->setIdentifier(array('id'));
$reflectionProperty = new \ReflectionProperty('Oro\\Bundle\\SearchBundle\\Tests\\Unit\\Formatter\\Stub\\Product', 'id');
$reflectionProperty->setAccessible(true);
$productMetadata->reflFields['id'] = $reflectionProperty;
// create category stubs
$categoryEntities = array();
for ($i = 1; $i <= 3; $i++) {
$indexerItem = new Item($this->entityManager, Category::getEntityName(), $i);
$entity = new Category($i);
$categoryEntities[$i] = $entity;
$this->categoryStubs[$i] = array('indexer_item' => $indexerItem, 'entity' => $entity);
}
$categoryMetadata = new ClassMetadata(Category::getEntityName());
$categoryMetadata->setIdentifier(array('id'));
$reflectionProperty = new \ReflectionProperty('Oro\\Bundle\\SearchBundle\\Tests\\Unit\\Formatter\\Stub\\Category', 'id');
$reflectionProperty->setAccessible(true);
$categoryMetadata->reflFields['id'] = $reflectionProperty;
// create metadata factory for stubs
$this->stubMetadata = new ClassMetadataFactory($this->entityManager);
$this->stubMetadata->setMetadataFor(Product::getEntityName(), $productMetadata);
$this->stubMetadata->setMetadataFor(Category::getEntityName(), $categoryMetadata);
$this->entityManager->expects($this->any())->method('getMetadataFactory')->will($this->returnValue($this->stubMetadata));
return array(Product::getEntityName() => $productEntities, Category::getEntityName() => $categoryEntities);
}
示例3: testHasRootEntityWithForeignKeyIdentifier
public function testHasRootEntityWithForeignKeyIdentifier()
{
$queryBuilder = $this->prophesize(QueryBuilder::class);
$queryBuilder->getRootEntities()->willReturn(['Dummy']);
$queryBuilder->getRootAliases()->willReturn(['d']);
$classMetadata = new ClassMetadata('Dummy');
$classMetadata->setIdentifier(['id', 'name']);
$objectManager = $this->prophesize(ObjectManager::class);
$objectManager->getClassMetadata('Dummy')->willReturn($classMetadata);
$managerRegistry = $this->prophesize(ManagerRegistry::class);
$managerRegistry->getManagerForClass('Dummy')->willReturn($objectManager->reveal());
$this->assertTrue(QueryChecker::hasRootEntityWithForeignKeyIdentifier($queryBuilder->reveal(), $managerRegistry->reveal()));
}
示例4: getMetadata
/**
* @return ClassMetadata
*/
public static function getMetadata()
{
$metadata = new ClassMetadata(static::class);
$metadata->setIdentifier(['id']);
$metadata->mapField(['fieldName' => 'id']);
$metadata->mapField(['fieldName' => 'a']);
$metadata->mapField(['fieldName' => 'b']);
$metadata->mapField(['fieldName' => 'c']);
$metadata->mapEmbedded(['fieldName' => 'd', 'class' => DummyEmbeddable::class, 'columnPrefix' => 'd']);
$metadata->mapManyToOne(['fieldName' => 'parent', 'targetEntity' => self::class, 'inversedBy' => 'children']);
$metadata->mapOneToMany(['fieldName' => 'children', 'targetEntity' => self::class, 'mappedBy' => 'parent']);
$metadata->wakeupReflection(new RuntimeReflectionService());
return $metadata;
}
示例5: testSetMultipleIdentifierSetsComposite
/**
* @group DDC-886
*/
public function testSetMultipleIdentifierSetsComposite()
{
$cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
$cm->mapField(array('fieldName' => 'name'));
$cm->mapField(array('fieldName' => 'username'));
$cm->setIdentifier(array('name', 'username'));
$this->assertTrue($cm->isIdentifierComposite);
}
示例6: testSetMultipleIdentifierSetsComposite
/**
* @group DDC-886
*/
public function testSetMultipleIdentifierSetsComposite()
{
$cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
$cm->mapField(array('fieldName' => 'name'));
$cm->mapField(array('fieldName' => 'username'));
$cm->setIdentifier(array('name', 'username'));
$this->assertTrue($cm->isIdentifierComposite);
}