public function setUp() { $this->class = 'Abc\\Bundle\\SequenceBundle\\Entity\\Sequence'; $this->classMetaData = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); $this->objectManager = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager'); $this->repository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository'); $this->objectManager->expects($this->any())->method('getClassMetadata')->will($this->returnValue($this->classMetaData)); $this->classMetaData->expects($this->any())->method('getName')->will($this->returnValue($this->class)); $this->objectManager->expects($this->any())->method('getRepository')->will($this->returnValue($this->repository)); $this->subject = new SequenceManager($this->objectManager, $this->class); }
/** * {@inheritdoc} */ public function setUp() { $this->class = Schedule::class; $this->classMetaData = $this->createMock(ClassMetadata::class); $this->objectManager = $this->createMock(ObjectManager::class); $this->repository = $this->createMock(ObjectRepository::class); $this->objectManager->expects($this->any())->method('getClassMetadata')->will($this->returnValue($this->classMetaData)); $this->classMetaData->expects($this->any())->method('getName')->will($this->returnValue($this->class)); $this->objectManager->expects($this->any())->method('getRepository')->will($this->returnValue($this->repository)); $this->subject = new ScheduleManager($this->objectManager, $this->class); }
/** * {@inheritdoc} */ public function setUp() { $this->class = Log::class; $this->classMetaData = $this->createMock(ClassMetadata::class); $this->objectManager = $this->createMock(ObjectManager::class); $this->repository = $this->createMock(ObjectRepository::class); $this->objectManager->expects($this->any())->method('getClassMetadata')->willReturn($this->classMetaData); $this->classMetaData->expects($this->any())->method('getName')->willReturn($this->class); $this->objectManager->expects($this->any())->method('getRepository')->willReturn($this->repository); $this->subject = $this->getMockForAbstractClass(LogManager::class, array($this->objectManager, $this->class)); }
public function setUp() { $this->class = ResourceLock::class; $this->classMetaData = $this->getMock(ClassMetadata::class); $this->objectManager = $this->getMock(ObjectManager::class); $this->repository = $this->getMock(ObjectRepository::class); $this->objectManager->expects($this->any())->method('getClassMetadata')->will($this->returnValue($this->classMetaData)); $this->classMetaData->expects($this->any())->method('getName')->will($this->returnValue($this->class)); $this->objectManager->expects($this->any())->method('getRepository')->will($this->returnValue($this->repository)); $this->subject = new LockManager($this->objectManager, $this->class, $this->prefix); }
public function setUp() { $this->class = 'Abc\\Bundle\\FileDistributionBundle\\Entity\\Definition'; $this->classMetaData = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); $this->objectManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $this->repository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository'); $this->objectManager->expects($this->any())->method('getClassMetadata')->will($this->returnValue($this->classMetaData)); $this->classMetaData->expects($this->any())->method('getName')->will($this->returnValue($this->class)); $this->objectManager->expects($this->any())->method('getRepository')->will($this->returnValue($this->repository)); $this->subject = new DefinitionManager($this->objectManager, $this->class); }
/** * {@inheritdoc} */ public function setUp() { $this->class = Job::class; $this->classMetaData = $this->createMock(ClassMetadata::class); $this->objectManager = $this->createMock(ObjectManager::class); $this->repository = $this->createMock(ObjectRepository::class); $this->scheduleManager = $this->getMockBuilder(ScheduleManager::class)->disableOriginalConstructor()->getMock(); $this->serializationHelper = $this->getMockBuilder(SerializationHelper::class)->disableOriginalConstructor()->getMock(); $this->objectManager->expects($this->any())->method('getClassMetadata')->willReturn($this->classMetaData); $this->classMetaData->expects($this->any())->method('getName')->willReturn($this->class); $this->objectManager->expects($this->any())->method('getRepository')->willReturn($this->repository); $this->subject = $this->getMockForAbstractClass(JobManager::class, [$this->objectManager, $this->class, $this->scheduleManager, $this->serializationHelper]); }
public function testCanHydrateOneToOneAssociationByReferenceWithNullableRelation() { // When using hydration by reference, it won't use the public API of the entity to retrieve values (setters) $entity = new Asset\OneToOneEntity(); $this->configureObjectManagerForOneToOneEntity(); $data = array('toOne' => null); $this->metadata->expects($this->once())->method('hasAssociation'); $object = $this->hydratorByReference->hydrate($data, $entity); $this->assertNull($object->getToOne(false)); }
/** * @expectedException \RuntimeException * @expectedExceptionMessage Expected Symfony\Component\Security\Core\Role\RoleInterface, \stdClass given */ public function testNotSupportedRole() { $user = new User(); $this->metadata->expects($this->once())->method('getAssociationTargetClass')->willReturn('\\stdClass'); $this->om->expects($this->never())->method('persist')->with($this->equalTo($user)); $this->om->expects($this->never())->method('flush'); $repository = $this->getMockBuilder('Oro\\Bundle\\UserBundle\\Entity\\Repository\\UserApiRepository')->disableOriginalConstructor()->getMock(); $this->om->expects($this->any())->method('getRepository')->will($this->returnValue($repository)); $this->userManager->updateUser($user); }
public function testLabelGeneratorUsedForGetValueOptions() { $this->prepareProxy(); $this->proxy->setOptions(array('label_generator' => function ($targetEntity) { return $targetEntity->getEmail(); })); $this->metadata->expects($this->never())->method('hasField'); $result = $this->proxy->getvalueOptions(); $this->assertEquals($result[0]['label'], 'object one email'); $this->assertEquals($result[1]['label'], 'object two email'); $this->assertEquals($result[0]['value'], 1); $this->assertEquals($result[1]['value'], 2); }
/** * @dataProvider iterationFlushesProvider * * @param int $resultItemsCount * @param int $batchSize * @param int $expectedFlushesCount */ public function testIterationFlushesAtGivenBatchSizes($resultItemsCount, $batchSize, $expectedFlushesCount) { $object = new \stdClass(); $values = array_fill(0, $resultItemsCount, $object); $iterator = SimpleBatchIteratorAggregate::fromArrayResult(array_fill(0, $resultItemsCount, $object), $this->entityManager, $batchSize); $this->metadata->expects(self::any())->method('getIdentifierValues')->willReturn(['id' => 123]); $this->entityManager->expects(self::exactly($resultItemsCount))->method('find')->willReturn($object); $this->entityManager->expects(self::exactly($expectedFlushesCount))->method('flush'); $this->entityManager->expects(self::exactly($expectedFlushesCount))->method('clear'); $iteratedObjects = []; foreach ($iterator as $key => $value) { $iteratedObjects[$key] = $value; } $this->assertCount($resultItemsCount, $iteratedObjects); }
public function testAvoidFailingLookupsForEmptyArrayValues() { $data = array('categories' => array(1, 2, '')); $reflClass = $this->getMock('\\ReflectionClass', array(), array('Doctrine\\Common\\Collections\\ArrayCollection')); $reflProperty = $this->getMock('\\ReflProperty', array('setAccessible', 'getValue')); $this->metadata->expects($this->exactly(1))->method('getTypeOfField')->with($this->equalTo('categories'))->will($this->returnValue('array')); $this->metadata->expects($this->exactly(1))->method('hasAssociation')->with($this->equalTo('categories'))->will($this->returnValue(true)); $this->metadata->expects($this->exactly(1))->method('getAssociationTargetClass')->with($this->equalTo('categories'))->will($this->returnValue('stdClass')); $this->metadata->expects($this->exactly(1))->method('isSingleValuedAssociation')->with($this->equalTo('categories'))->will($this->returnValue(false)); $this->metadata->expects($this->exactly(1))->method('isCollectionValuedAssociation')->with($this->equalTo('categories'))->will($this->returnValue(true)); $this->objectManager->expects($this->exactly(2))->method('find')->will($this->returnValue(new stdClass())); $this->metadata->expects($this->exactly(1))->method('getReflectionClass')->will($this->returnValue($reflClass)); $reflClass->expects($this->exactly(1))->method('getProperty')->with($this->equalTo('categories'))->will($this->returnValue($reflProperty)); $reflProperty->expects($this->exactly(1))->method('getValue')->withAnyParameters()->will($this->returnValue(new ArrayCollection($data))); $object = $this->hydrator->hydrate($data, new stdClass()); $this->assertEquals(2, count($object->categories)); }
public function testHydrateOneToManyAssociationByReferenceWithArrayCausingDataModifications() { // When using hydration by value, it will use the public API of the entity to set values (setters) $data = array('entities' => array(array('id' => 2, 'field' => 'Modified By Hydrate'), array('id' => 3, 'field' => 'Modified By Hydrate'))); $entityInDatabaseWithIdOfTwo = new Asset\SimpleEntity(); $entityInDatabaseWithIdOfTwo->setId(2); $entityInDatabaseWithIdOfTwo->setField('Unmodified Value', false); $entityInDatabaseWithIdOfThree = new Asset\SimpleEntity(); $entityInDatabaseWithIdOfThree->setId(3); $entityInDatabaseWithIdOfThree->setField('Unmodified Value', false); $entity = new Asset\OneToManyEntityWithEntities(new ArrayCollection(array($entityInDatabaseWithIdOfTwo, $entityInDatabaseWithIdOfThree))); $reflSteps = array(new ReflectionClass('DoctrineModuleTest\\Stdlib\\Hydrator\\Asset\\OneToManyEntityWithEntities'), new ReflectionClass('DoctrineModuleTest\\Stdlib\\Hydrator\\Asset\\SimpleEntity'), new ReflectionClass('DoctrineModuleTest\\Stdlib\\Hydrator\\Asset\\SimpleEntity'), new ReflectionClass('DoctrineModuleTest\\Stdlib\\Hydrator\\Asset\\OneToManyEntityWithEntities')); $this->metadata->expects($this->any())->method('getReflectionClass')->will($this->returnCallback(function () use(&$reflSteps) { $refl = array_shift($reflSteps); return $refl; })); $this->configureObjectManagerForOneToManyEntity(); $this->objectManager->expects($this->exactly(2))->method('find')->with('DoctrineModuleTest\\Stdlib\\Hydrator\\Asset\\SimpleEntity', $this->logicalOr($this->equalTo(array('id' => 2)), $this->equalTo(array('id' => 3))))->will($this->returnCallback(function ($target, $arg) use($entityInDatabaseWithIdOfTwo, $entityInDatabaseWithIdOfThree) { if ($arg['id'] === 2) { return $entityInDatabaseWithIdOfTwo; } elseif ($arg['id'] === 3) { return $entityInDatabaseWithIdOfThree; } throw new \InvalidArgumentException(); })); $entity = $this->hydratorByReference->hydrate($data, $entity); $this->assertInstanceOf('DoctrineModuleTest\\Stdlib\\Hydrator\\Asset\\OneToManyEntityWithEntities', $entity); /* @var $entity \DoctrineModuleTest\Stdlib\Hydrator\Asset\OneToManyEntity */ $entities = $entity->getEntities(false); foreach ($entities as $en) { $this->assertInstanceOf('DoctrineModuleTest\\Stdlib\\Hydrator\\Asset\\SimpleEntity', $en); $this->assertInternalType('integer', $en->getId()); $this->assertInternalType('string', $en->getField()); $this->assertContains('Modified By Hydrate', $en->getField(false)); } $this->assertEquals(2, $entities[0]->getId()); $this->assertSame($entityInDatabaseWithIdOfTwo, $entities[0]); $this->assertEquals(3, $entities[1]->getId()); $this->assertSame($entityInDatabaseWithIdOfThree, $entities[1]); }