public function testCreatesRepositoryFromCustomClassMetadata() { $customMetadata = $this->buildClassMetadata(__DIR__); $customMetadata->customRepositoryClassName = 'Doctrine\\Tests\\Models\\DDC753\\DDC753DefaultRepository'; $this->entityManager->expects($this->any())->method('getClassMetadata')->will($this->returnValue($customMetadata)); $this->assertInstanceOf('Doctrine\\Tests\\Models\\DDC753\\DDC753DefaultRepository', $this->repositoryFactory->getRepository($this->entityManager, __CLASS__)); }
/** * Test fail execute * * @expectedException \InvalidArgumentException * @expectedExceptionMessage Some exception */ public function testExecuteFail() { $this->em->expects($this->at(0))->method('beginTransaction'); $this->em->expects($this->at(1))->method('rollback'); $transactional = new DoctrineORMTransactional($this->em); $transactional->execute(function () { throw new \InvalidArgumentException('Some exception'); }); }
protected function setUp() { $this->connection = $this->getMock('Doctrine\\DBAL\\Connection', [], [], '', false); $this->configuration = $this->getMock('Doctrine\\ORM\\Configuration'); $this->em = $this->getMock('Doctrine\\ORM\\EntityManagerInterface'); $this->em->expects($this->any())->method('getConnection')->willReturn($this->connection); $this->em->expects($this->any())->method('getConfiguration')->willReturn($this->configuration); $this->connection->expects($this->any())->method('getDatabasePlatform')->willReturn(new MySqlPlatform()); $this->schemaTool = $this->getMock('Oro\\Bundle\\EntityExtendBundle\\Tools\\SaveSchemaTool', ['getSchemaFromMetadata'], [$this->em]); }
public function testGetUserSetting() { $setting = 'allow_email'; $user = new User(); $settingValue = new SettingValue(); $settingValue->setValue('allow'); $objectRepository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository'); $this->objectManager->expects($this->once())->method('getRepository')->with('Eye4web\\ZfcUser\\Settings\\Entity\\SettingValue')->will($this->returnValue($objectRepository)); $objectRepository->expects($this->once())->method('findOneBy')->with(['user' => $user->getId(), 'setting' => $setting])->will($this->returnValue($settingValue)); $this->assertSame($settingValue, $this->mapper->getUserSetting($setting, $user)); }
public function testPrePersistHandlerWhenKeyDoesNotExistYet() { $branch = new Branch('DUMM', 'Dummy', 'Desc'); $event = new LifecycleEventArgs($branch, $this->objectManager); $dqlQueryStr = "SELECT b FROM DiamanteDeskBundle:Branch b WHERE b.key = :key"; $query = $this->getMockBuilder('\\Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(array('setParameter', 'getResult'))->getMockForAbstractClass(); $this->objectManager->expects($this->once())->method('createQuery')->with($dqlQueryStr)->will($this->returnValue($query)); $query->expects($this->once())->method('setParameter')->with('key', $branch->getKey())->will($this->returnValue($query)); $query->expects($this->once())->method('getResult')->will($this->returnValue(array())); $listener = new BranchListener(); $listener->prePersistHandler($branch, $event); }
/** * @param EntityManagerInterface $em * @param AbstractManager $manager * @param string $class * @param string $entityFullName * @param null $container */ public function addManagerTest($em, $manager, $class, $entityFullName, $container = null) { $entity = $manager->create($container); $this->assertInstanceOf($class, $entity); $this->assertEquals($class, $manager->getClass()); $this->assertTrue($manager->supports(new $class($container))); $em->expects($this->exactly(2))->method('persist')->with($this->equalTo($entity)); $em->expects($this->once(1))->method('refresh')->with($this->equalTo($entity)); $em->expects($this->atLeastOnce())->method('getRepository')->with($this->equalTo($entityFullName)); $em->expects($this->exactly(2))->method('flush'); $manager->getRepository(); $this->assertEquals($manager, $manager->persist($entity)); $this->assertEquals($manager, $manager->flush()); $manager->persist($entity, true); $this->assertEquals($manager, $manager->refresh($entity)); }
public function testPrePersistHandler() { $branchId = 1; $ticketSequenceNumberValue = 9; $branch = new BranchStub('DB', 'Dummy Branch', 'Desc'); $branch->setId($branchId); $reporter = new User(1, User::TYPE_DIAMANTE); $ticket = new Ticket(new UniqueId('unique_id'), new TicketSequenceNumber(null), 'Subject', 'Description', $branch, $reporter, new OroUser(), new Source(Source::WEB), new Priority(Priority::PRIORITY_MEDIUM), new Status(Status::NEW_ONE)); $event = new LifecycleEventArgs($ticket, $this->objectManager); $dqlQueryStr = "SELECT MAX(t.sequenceNumber) FROM DiamanteDeskBundle:Ticket t WHERE t.branch = :branchId"; $query = $this->getMockBuilder('\\Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(array('setParameter', 'getSingleScalarResult'))->getMockForAbstractClass(); $this->objectManager->expects($this->once())->method('createQuery')->with($dqlQueryStr)->will($this->returnValue($query)); $query->expects($this->once())->method('setParameter')->with('branchId', $branchId)->will($this->returnValue($query)); $query->expects($this->once())->method('getSingleScalarResult')->will($this->returnValue($ticketSequenceNumberValue)); $this->listener->prePersistHandler($ticket, $event); $this->assertEquals($ticketSequenceNumberValue + 1, $ticket->getSequenceNumber()->getValue()); }
/** * @param bool $isChangesExists */ protected function configureUnitOfWork($isChangesExists) { $uowMock = $this->getMockBuilder('\\Doctrine\\ORM\\UnitOfWork')->disableOriginalConstructor()->getMock(); $this->manager->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($uowMock)); $uowMock->expects($this->once())->method('computeChangeSets'); $uowMock->expects($this->once())->method('getEntityChangeSet')->with($this->entity)->will($this->returnValue($isChangesExists ? [1] : [])); $uowMock->expects($this->once())->method('getScheduledEntityUpdates')->will($this->returnValue([1])); }
/** * Test on updated propose update task. */ public function testOnUpdatedProposeUpdateTask() { $that = $this; $next_run = new \DateTime(); $next_run->modify('+' . ProposeUpdateCommand::INERVAL_UPDATE . ' seconds 01:00:00'); $task = $this->getMock('\\AnimeDb\\Bundle\\AppBundle\\Entity\\Task'); $task->expects($this->once())->method('setNextRun')->will($this->returnCallback(function ($date) use($that, $next_run, $task) { $that->assertEquals($next_run, $date); return $task; })); $rep = $this->getMockBuilder('\\Doctrine\\Common\\Persistence\\ObjectRepository')->disableOriginalConstructor()->getMockForAbstractClass(); $rep->expects($this->any())->method('findOneBy')->will($this->returnValue($task))->with(['command' => 'animedb:propose-update']); $this->em->expects($this->once())->method('getRepository')->with('AnimeDbAppBundle:Task')->will($this->returnValue($rep)); $this->em->expects($this->once())->method('persist')->with($task); $this->em->expects($this->once())->method('flush'); // test $this->listener->onUpdatedProposeUpdateTask(); }
public function testOnRemovedRemovePlugin() { $plugin = $this->getMock('\\AnimeDb\\Bundle\\AppBundle\\Entity\\Plugin'); $this->rep->expects($this->once())->method('find')->will($this->returnValue($plugin))->with('foo/bar'); $this->em->expects($this->once())->method('remove')->with($plugin); $this->em->expects($this->once())->method('flush'); // test $event = '\\AnimeDb\\Bundle\\AnimeDbBundle\\Event\\Package\\Removed'; $this->listener->onRemoved($this->getEvent($this->getPackage(), $event)); }
/** * Tests the dump() method with an entity. */ public function testDumpWithAnEntity() { if (!method_exists($this->filesystem, 'dumpFile')) { $this->markTestSkipped('Test skipped as Filesystem::dumpFile() is not available in this version.'); } // Given $this->service->setRootDir('/unit/test/'); $this->service->setFilename('feed.rss'); $this->service->setEntity('Eko\\FeedBundle\\Tests\\Entity\\Writer\\FakeItemInterfaceEntity'); $this->service->setDirection('ASC'); $entity = $this->getMock('Eko\\FeedBundle\\Tests\\Entity\\Writer\\FakeItemInterfaceEntity'); $repository = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); $repository->expects($this->once())->method('findBy')->will($this->returnValue([$entity, $entity])); $this->entityManager->expects($this->once())->method('getRepository')->will($this->returnValue($repository)); $feed = $this->getMockBuilder('Eko\\FeedBundle\\Feed\\Feed')->disableOriginalConstructor()->getMock(); $feed->expects($this->once())->method('addFromArray'); $feed->expects($this->once())->method('render')->will($this->returnValue('XML content')); $this->feedManager->expects($this->once())->method('get')->will($this->returnValue($feed)); $this->filesystem->expects($this->once())->method('dumpFile')->with('/unit/test/feed.rss', 'XML content'); // When - Expects actions $this->service->dump(); }
/** * @dataProvider getEntityIdentifier * * @param array $ids */ public function testGetEntityIdentifier(array $ids) { $entity = new Bar(); $meta = $this->getNoConstructorMock(ClassMetadata::class); $meta->expects($this->once())->method('getIdentifierValues')->with($entity)->will($this->returnValue($ids)); $this->doctrine->expects($this->once())->method('getManager')->will($this->returnValue($this->em)); $this->em->expects($this->once())->method('getClassMetadata')->with(get_class($entity))->will($this->returnValue($meta)); $prefix = null; if ($ids) { $prefix = CacheKeyBuilder::IDENTIFIER_PREFIX . implode(CacheKeyBuilder::IDENTIFIER_SEPARATOR, $ids); } $this->assertEquals($prefix, $this->builder->getEntityIdentifier($entity)); }
/** * @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); }
/** * Checks if the importer detaches the provided entities. */ public function testImporterDetachesEntities() { $this->entityManager->expects($this->exactly(2))->method('detach')->with($this->isInstanceOf('\\stdClass')); $entities = array(new \stdClass(), new \stdClass()); $this->importer->import($entities); }