本文整理匯總了PHP中Doctrine\ORM\EntityManagerInterface::expects方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityManagerInterface::expects方法的具體用法?PHP EntityManagerInterface::expects怎麽用?PHP EntityManagerInterface::expects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\ORM\EntityManagerInterface
的用法示例。
在下文中一共展示了EntityManagerInterface::expects方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testCreatesRepositoryFromCustomClassMetadata
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__));
}
示例2: testExecuteFail
/**
* 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');
});
}
示例3: setUp
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]);
}
示例4: testGetUserSetting
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));
}
示例5: testPrePersistHandlerWhenKeyDoesNotExistYet
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);
}
示例6: addManagerTest
/**
* @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));
}
示例7: testPrePersistHandler
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());
}
示例8: configureUnitOfWork
/**
* @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]));
}
示例9: testOnUpdatedProposeUpdateTask
/**
* 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();
}
示例10: testOnRemovedRemovePlugin
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));
}
示例11: testDumpWithAnEntity
/**
* 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();
}
示例12: testGetEntityIdentifier
/**
* @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));
}
示例13: testIterationFlushesAtGivenBatchSizes
/**
* @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);
}
示例14: testImporterDetachesEntities
/**
* 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);
}