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)); }
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); }
/** * @test */ public function thatApiUserRetrievesByUsername() { $email = '*****@*****.**'; $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); }
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); }
/** * @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); }
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); }
/** * @test */ public function thatGetsAll() { $entities = array(new EntityStub(), new EntityStub()); $this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->unitOfWork)); $this->unitOfWork->expects($this->once())->method('getEntityPersister')->with($this->equalTo(self::CLASS_NAME))->will($this->returnValue($this->entityPersister)); $this->entityPersister->expects($this->once())->method('loadAll')->with($this->equalTo(array()), $this->equalTo(null), $this->equalTo(null), $this->equalTo(null))->will($this->returnValue($entities)); $retrievedEntities = $this->repository->getAll(); $this->assertEquals($entities, $retrievedEntities); }
public function testListAllByUserAndPeriod() { $user = new User(); $period = new Period(new \DateTime('2014-12-01'), new \DateTime('2014-12-31')); $worklogs = [$this->worklog()]; $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('loadCriteria')->with($this->logicalAnd($this->isInstanceOf('\\Doctrine\\Common\\Collections\\Criteria')))->will($this->returnValue($worklogs)); $result = $this->repository->listAllByUserAndPeriod($user, $period); $this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $result); $this->assertEquals($result->toArray(), $worklogs); }
/** * @test */ public function persistAllRespectsObjectWhitelistIfOnlyWhitelistedObjectsFlagIsTrue() { $mockObject = new \stdClass(); $scheduledEntityUpdates = array(spl_object_hash($mockObject) => $mockObject); $scheduledEntityDeletes = array(); $scheduledEntityInsertions = array(); $this->mockUnitOfWork->expects($this->any())->method('getScheduledEntityUpdates')->will($this->returnValue($scheduledEntityUpdates)); $this->mockUnitOfWork->expects($this->any())->method('getScheduledEntityDeletions')->will($this->returnValue($scheduledEntityDeletes)); $this->mockUnitOfWork->expects($this->any())->method('getScheduledEntityInsertions')->will($this->returnValue($scheduledEntityInsertions)); $this->mockEntityManager->expects($this->once())->method('flush'); $this->persistenceManager->whitelistObject($mockObject); $this->persistenceManager->persistAll(true); }
/** * @dataProvider defaultIntegrationOwnerProvider * * @param Integration $integration * @param string $ownerType * @param bool $expectedReload * @param bool $expectedSet * @param bool $expectedSetOrganization */ public function testPopulateChannelOwner(Integration $integration, $ownerType, $expectedReload, $expectedSet, $expectedSetOrganization = false) { $entity = new \stdClass(); $owner = $integration->getDefaultUserOwner(); $organization = $integration->getOrganization(); $doctrineMetadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadataInfo')->disableOriginalConstructor()->getMock(); $this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($doctrineMetadata)); if ($expectedReload) { $this->uow->expects($this->once())->method('getEntityState')->with($this->identicalTo($owner))->will($this->returnValue(UnitOfWork::STATE_DETACHED)); $this->em->expects($this->once())->method('find')->with($this->equalTo(get_class($owner)))->will($this->returnValue($owner)); } $ownerMetadata = new OwnershipMetadata($ownerType, self::USER_OWNER_FIELD_NAME, self::USER_OWNER_COLUMN_NAME, self::ORGANIZATION_FIELD_NAME); $this->metadataProvider->expects($this->any())->method('getMetadata')->with(get_class($entity))->will($this->returnValue($ownerMetadata)); if ($expectedSet) { $doctrineMetadata->expects($this->once())->method('setFieldValue')->with($this->identicalTo($entity), self::USER_OWNER_FIELD_NAME, $this->identicalTo($owner)); } elseif ($expectedSetOrganization) { $doctrineMetadata->expects($this->once())->method('setFieldValue')->with($this->identicalTo($entity), self::ORGANIZATION_FIELD_NAME, $this->identicalTo($organization)); } else { $doctrineMetadata->expects($this->never())->method('setFieldValue'); } $this->helper->populateChannelOwner($entity, $integration); }
public function testFlush() { $changesetAnswer = ['seen' => true]; $user1 = new User(); $user1->setId(1); $user2 = new User(); $user2->setId(2); $emailUser1 = new EmailUser(); $emailUser1->setOwner($user1); $emailUser2 = new EmailUser(); $emailUser2->setOwner($user2); $emailUserArray = [$emailUser1, $emailUser2, $emailUser1]; $onFlushEventArgs = $this->getMockBuilder('Doctrine\\ORM\\Event\\OnFlushEventArgs')->setMethods(['getEntityManager'])->disableOriginalConstructor()->getMock(); $onFlushEventArgs->expects($this->once())->method('getEntityManager')->will($this->returnValue($this->em)); $this->uow->expects($this->any())->method('getEntityChangeSet')->will($this->returnValue($changesetAnswer)); $this->uow->expects($this->any())->method('getScheduledEntityInsertions')->will($this->returnValue($emailUserArray)); $this->uow->expects($this->any())->method('getScheduledEntityUpdates')->will($this->returnValue($emailUserArray)); $this->processor->expects($this->exactly(1))->method('send')->with([$user1->getId() => ['entity' => $emailUser1, 'new' => 2], $user2->getId() => ['entity' => $emailUser2, 'new' => 1]]); $postFlushEventArgs = $this->getMockBuilder('Doctrine\\ORM\\Event\\PostFlushEventArgs')->disableOriginalConstructor()->getMock(); $postFlushEventArgs->expects($this->any())->method('getEntityManager')->willReturn($this->em); $this->listener->onFlush($onFlushEventArgs); $this->listener->postFlush($postFlushEventArgs); }
public function testScheduleEntityUpdate() { $account = $this->getMock('OroCRM\\Bundle\\AccountBundle\\Entity\\Account'); $channel = $this->getMock('OroCRM\\Bundle\\ChannelBundle\\Entity\\Channel'); $customer = new CustomerEntity(); $customer->setAccount($account)->setDataChannel($channel); $this->uow->expects($this->exactly(2))->method('isScheduledForDelete')->willReturn(false); $reflectionProperty = new \ReflectionProperty(get_class($this->channelDoctrineListener), 'uow'); $reflectionProperty->setAccessible(true); $reflectionProperty->setValue($this->channelDoctrineListener, $this->uow); $this->assertAttributeEmpty('queued', $this->channelDoctrineListener); $this->channelDoctrineListener->scheduleEntityUpdate($customer, $account, $channel); $this->assertAttributeNotEmpty('queued', $this->channelDoctrineListener); }
/** * @dataProvider collectNestingDataDataProvider * * @param array $associations * @param array $mappings * @param int $expectedCount */ public function testCollectNestingData($associations, $mappings, $expectedCount) { $testData = new EntityStub(); $reflection = new \ReflectionMethod($this->generator, 'collectNestedDataTags'); $reflection->setAccessible(true); $this->uow->expects($this->any())->method('getEntityIdentifier')->will($this->returnValue(['someIdentifierValue'])); $metadata = new ClassMetadata(self::TEST_ENTITY_NAME); $metadata->associationMappings = $mappings; foreach ($associations as $name => $dataValue) { $field = $this->getMockBuilder('\\ReflectionProperty')->disableOriginalConstructor()->getMock(); $field->expects($this->once())->method('getValue')->with($testData)->will($this->returnValue($dataValue)); $metadata->reflFields[$name] = $field; } $result = $reflection->invoke($this->generator, $testData, $metadata); $this->assertInternalType('array', $result, 'Should always return array'); $this->assertCount($expectedCount, $result, 'Should not generate collection tag for associations'); }