本文整理汇总了PHP中Doctrine\ORM\UnitOfWork类的典型用法代码示例。如果您正苦于以下问题:PHP UnitOfWork类的具体用法?PHP UnitOfWork怎么用?PHP UnitOfWork使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UnitOfWork类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function it_clears_the_import_cache(DoctrineCache $doctrineCache, EntityManager $entityManager, UnitOfWork $uow)
{
$this->setNonClearableEntities(['NonClearable']);
$uow->getIdentityMap()->willReturn(['NonClearable' => [], 'Clearable' => []]);
$entityManager->clear('Clearable')->shouldBeCalled();
$doctrineCache->clear(['NonClearable'])->shouldBeCalled();
$this->clear();
}
示例2: testRetrieveUserTracker
public function testRetrieveUserTracker()
{
$user = new User();
$tracker = $this->tracker();
$this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->unitOfWork));
$this->unitOfWork->expects($this->once())->method('getEntityPersister')->with(self::CLASS_NAME)->will($this->returnValue($this->entityPersister));
$this->entityPersister->expects($this->once())->method('load')->with(['user' => $user], null, null, [], 0, 1, null)->will($this->returnValue($tracker));
$this->repository->retrieveUserTracker($user);
}
示例3: isValidEntityState
/**
* Check if entity is in a valid state for operations.
*
* @param object $entity
*
* @return bool
*/
protected function isValidEntityState($entity)
{
$entityState = $this->uow->getEntityState($entity, UnitOfWork::STATE_NEW);
if ($entityState === UnitOfWork::STATE_NEW) {
return false;
}
// If Entity is scheduled for inclusion, it is not in this collection.
// We can assure that because it would have return true before on array check
return !($entityState === UnitOfWork::STATE_MANAGED && $this->uow->isScheduledForInsert($entity));
}
示例4: thatApiUserRetrievesByUsername
/**
* @test
*/
public function thatApiUserRetrievesByUsername()
{
$email = 'test@domain.com';
$apiUser = $this->getApiUser();
$this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->unitOfWork));
$this->unitOfWork->expects($this->once())->method('getEntityPersister')->with($this->equalTo(self::DUMMY_CLASS_NAME))->will($this->returnValue($this->entityPersister));
$this->entityPersister->expects($this->once())->method('load')->with($this->equalTo(array('email' => $email)), $this->equalTo(null), $this->equalTo(null), array(), $this->equalTo(0), $this->equalTo(1), $this->equalTo(null))->will($this->returnValue($apiUser));
$retrievedApiUser = $this->repository->findOneBy(array('email' => $email));
$this->assertNotNull($retrievedApiUser);
$this->assertEquals($apiUser, $retrievedApiUser);
}
示例5: testFindAllByTicket
public function testFindAllByTicket()
{
$messageReference = $this->getMessageReference();
$ticket = $messageReference->getTicket();
$references = array($messageReference);
$this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->unitOfWork));
$this->unitOfWork->expects($this->once())->method('getEntityPersister')->with($this->equalTo(self::DUMMY_CLASS_NAME))->will($this->returnValue($this->entityPersister));
$this->entityPersister->expects($this->once())->method('loadAll')->with($this->equalTo(array('ticket' => $ticket)), null, null, null)->will($this->returnValue($references));
$result = $this->repository->findAllByTicket($ticket);
$this->assertEquals($references, $result);
}
示例6: thatBranchEmailConfigurationRetrievesByBranchId
/**
* @test
*/
public function thatBranchEmailConfigurationRetrievesByBranchId()
{
$branchId = 1;
$branchEmailConfiguration = $this->getBranchEmailConfiguartion();
$this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->unitOfWork));
$this->unitOfWork->expects($this->once())->method('getEntityPersister')->with($this->equalTo(self::DUMMY_CLASS_NAME))->will($this->returnValue($this->entityPersister));
$this->entityPersister->expects($this->once())->method('load')->with($this->equalTo(array('branchId' => $branchId)), $this->equalTo(null), $this->equalTo(null), array(), $this->equalTo(0), $this->equalTo(1), $this->equalTo(null))->will($this->returnValue($branchEmailConfiguration));
$retrievedBranchEmailConfiguration = $this->repository->findOneBy(array('branchId' => $branchId));
$this->assertNotNull($retrievedBranchEmailConfiguration);
$this->assertEquals($branchEmailConfiguration, $retrievedBranchEmailConfiguration);
}
开发者ID:northdakota,项目名称:DiamanteDeskBundle,代码行数:14,代码来源:DoctrineBranchEmailConfigurationRepositoryTest.php
示例7: getChangeSet
/**
* Get an array describing the changes.
*
* @param UnitOfWork $unitOfWork
* @param TermOfUse $entity
* @param string $action
*
* @return array
*/
protected function getChangeSet(UnitOfWork $unitOfWork, TermOfUse $entity, $action)
{
switch ($action) {
case 'create':
return array('id' => array(null, $entity->getId()), 'weight' => array(null, $entity->getWeight()), 'keyCode' => array(null, $entity->getKeyCode()), 'langCode' => array(null, $entity->getLangCode()), 'content' => array(null, $entity->getContent()), 'created' => array(null, $entity->getCreated()), 'updated' => array(null, $entity->getUpdated()));
case 'update':
return $unitOfWork->getEntityChangeSet($entity);
case 'delete':
return array('id' => array($entity->getId(), null), 'weight' => array($entity->getWeight(), null), 'keyCode' => array($entity->getKeyCode(), null), 'langCode' => array($entity->getLangCode(), null), 'content' => array($entity->getContent(), null), 'created' => array($entity->getCreated(), null), 'updated' => array($entity->getUpdated(), null));
}
}
示例8: processInsertionOrUpdateEntity
/**
* @param $emailField
* @param mixed $entity
* @param EmailOwnerInterface $owner
* @param EntityManager $em
* @param UnitOfWork $uow
*/
protected function processInsertionOrUpdateEntity($emailField, $entity, EmailOwnerInterface $owner, EntityManager $em, UnitOfWork $uow)
{
if (!empty($emailField)) {
foreach ($uow->getEntityChangeSet($entity) as $field => $vals) {
if ($field === $emailField) {
list($oldValue, $newValue) = $vals;
if ($newValue !== $oldValue) {
$this->bindEmailAddress($em, $owner, $newValue, $oldValue);
}
}
}
}
}
示例9: setUp
public function setUp()
{
$this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
$this->uow = $this->getMockBuilder('Doctrine\\ORM\\UnitOfWork')->disableOriginalConstructor()->getMock();
$this->persister = $this->getMockBuilder('Doctrine\\ORM\\Persisters\\BasicEntityPersister')->disableOriginalConstructor()->getMock();
$this->em->expects($this->any())->method('getUnitOfWork')->will($this->returnValue($this->uow));
$this->uow->expects($this->any())->method('getEntityPersister')->with('stdClass')->will($this->returnValue($this->persister));
$this->entity = new stdClass();
$metadata = new ClassMetadata('stdClass');
$metadata->fieldMappings = array('property' => 'property');
$metadata->identifier = array('id');
$this->repository = new EntityRepository($this->em, $metadata);
}
示例10: createCalendar
/**
* @param EntityManager $em
* @param UnitOfWork $uow
* @param User $entity
* @param Organization $organization
*/
protected function createCalendar($em, $uow, $entity, $organization)
{
// create a default calendar for assigned organization
$calendar = new Calendar();
$calendar->setOwner($entity);
$calendar->setOrganization($organization);
// connect the calendar to itself
$calendarConnection = new CalendarConnection($calendar);
$calendar->addConnection($calendarConnection);
$em->persist($calendar);
$em->persist($calendarConnection);
$uow->computeChangeSet($this->getClassMetadata($calendar, $em), $calendar);
$uow->computeChangeSet($this->getClassMetadata($calendarConnection, $em), $calendarConnection);
}
示例11: flattenIdentifier
/**
* convert foreign identifiers into scalar foreign key values to avoid object to string conversion failures.
*
* @param ClassMetadata $class
* @param array $id
*
* @return array
*/
public function flattenIdentifier(ClassMetadata $class, array $id)
{
$flatId = array();
foreach ($class->identifier as $field) {
if (isset($class->associationMappings[$field]) && isset($id[$field]) && is_object($id[$field])) {
/* @var $targetClassMetadata ClassMetadata */
$targetClassMetadata = $this->metadataFactory->getMetadataFor($class->associationMappings[$field]['targetEntity']);
if ($this->unitOfWork->isInIdentityMap($id[$field])) {
$associatedId = $this->flattenIdentifier($targetClassMetadata, $this->unitOfWork->getEntityIdentifier($id[$field]));
} else {
$associatedId = $this->flattenIdentifier($targetClassMetadata, $targetClassMetadata->getIdentifierValues($id[$field]));
}
$flatId[$field] = implode(' ', $associatedId);
} elseif (isset($class->associationMappings[$field])) {
$associatedId = array();
foreach ($class->associationMappings[$field]['joinColumns'] as $joinColumn) {
$associatedId[] = $id[$joinColumn['name']];
}
$flatId[$field] = implode(' ', $associatedId);
} else {
$flatId[$field] = $id[$field];
}
}
return $flatId;
}
示例12: testSourceModified
public function testSourceModified()
{
$changeset = ['datetimeLastVisited' => [null, new \DateTime()], 'data' => [null, ['foo' => 'bar']]];
$this->uow->expects($this->once())->method('getEntityChangeSet')->will($this->returnValue($changeset));
$listener = new SourceModificationListenerMock($this->sourceProcessor, $this->queueManager);
$this->assertTrue($listener->visibleIsSourceModified(new SourceMock(12345), $this->uow));
}
示例13: onFlush
public function onFlush(OnFlushEventArgs $e)
{
$this->init($e);
foreach ($this->uow->getScheduledEntityInsertions() as $entity) {
if ($entity instanceof RoundedEntityInterface) {
$entity->setRound($this->round);
$this->uow->recomputeSingleEntityChangeSet($this->em->getClassMetadata(get_class($entity)), $entity);
}
}
//$this->uow->computeChangeSets();
}
示例14: transform
/**
* @param Object $entity
* @return string
*/
public function transform($entity)
{
if (null === $entity || '' === $entity) {
return 'null';
}
if (!is_object($entity)) {
throw new UnexpectedTypeException($entity, 'object');
}
if (!$this->unitOfWork->isInIdentityMap($entity)) {
throw new InvalidArgumentException('Entities passed to the choice field must be managed');
}
return $entity->getId();
}
示例15: flattenIdentifier
/**
* convert foreign identifiers into scalar foreign key values to avoid object to string conversion failures.
*
* @param \Doctrine\ORM\Mapping\ClassMetadata $class
* @param array $id
* @return array
*/
public function flattenIdentifier(ClassMetadata $class, array $id)
{
$flatId = array();
foreach ($id as $idField => $idValue) {
if (isset($class->associationMappings[$idField]) && is_object($idValue)) {
$targetClassMetadata = $this->metadataFactory->getMetadataFor($class->associationMappings[$idField]['targetEntity']);
$associatedId = $this->unitOfWork->getEntityIdentifier($idValue);
$flatId[$idField] = $associatedId[$targetClassMetadata->identifier[0]];
} else {
$flatId[$idField] = $idValue;
}
}
return $flatId;
}