本文整理汇总了PHP中Doctrine\ORM\EntityManager::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::expects方法的具体用法?PHP EntityManager::expects怎么用?PHP EntityManager::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\EntityManager
的用法示例。
在下文中一共展示了EntityManager::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testNext
public function testNext()
{
$expectedResults = array(array(1), array(5), array(7));
$query = new MockQuery();
$query->setNextResult($expectedResults);
$createQuery = function ($dql) use($query) {
$query->setDQL($dql);
return $query;
};
$this->em->expects($this->any())->method('createQuery')->will($this->returnCallback($createQuery));
$qb = new \Doctrine\ORM\QueryBuilder($this->em);
$qb->select('a.id, a.name')->from('A', 'a')->where('a.name = :name')->setParameter('name', 'abc');
// initialize Iterator
$this->object->setQueryBuilder($qb);
$this->object->setIterateBy('a.id');
$this->object->setPageSize(3);
$this->object->setPullClosure(function ($arr) {
return $arr[0];
});
// initial results
$this->assertEquals($expectedResults, $this->object->next());
$this->assertEquals('SELECT a.id, a.name FROM A a WHERE a.name = :name ORDER BY a.id ASC', $query->getDQL());
$this->assertEquals(3, $query->getLastMaxResults());
$this->assertEquals(1, \count($query->getLastParameters()));
// second results
$query->setNextResult(array());
$this->assertEquals(array(), $this->object->next());
$this->assertEquals('SELECT a.id, a.name FROM A a WHERE a.name = :name AND a.id > 7 ORDER BY a.id ASC', $query->getDQL());
$this->assertEquals(3, $query->getLastMaxResults());
$this->assertEquals(1, \count($query->getLastParameters()));
}
示例2: testBuild
public function testBuild()
{
$type = 'history';
$userId = 1;
$user = $this->getMockBuilder('stdClass')->setMethods(['getId'])->getMock();
$user->expects($this->once())->method('getId')->will($this->returnValue($userId));
$token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
$token->expects($this->once())->method('getUser')->will($this->returnValue($user));
$this->tokenStorage->expects($this->once())->method('getToken')->will($this->returnValue($token));
$item = $this->getMock('Oro\\Bundle\\NavigationBundle\\Entity\\NavigationItemInterface');
$this->factory->expects($this->once())->method('createItem')->with($type, [])->will($this->returnValue($item));
$repository = $this->getMockBuilder('Oro\\Bundle\\NavigationBundle\\Entity\\Repository\\HistoryItemRepository')->disableOriginalConstructor()->getMock();
$items = [['id' => 1, 'title' => 'test1', 'url' => '/'], ['id' => 2, 'title' => 'test2', 'url' => '/home']];
$repository->expects($this->once())->method('getNavigationItems')->with($userId, $type)->will($this->returnValue($items));
$this->em->expects($this->once())->method('getRepository')->with(get_class($item))->will($this->returnValue($repository));
$menu = $this->getMockBuilder('Knp\\Menu\\MenuItem')->disableOriginalConstructor()->getMock();
$childMock = $this->getMock('Knp\\Menu\\ItemInterface');
$childMock2 = clone $childMock;
$children = [$childMock, $childMock2];
$matcher = $this->getMock('\\Knp\\Menu\\Matcher\\Matcher');
$matcher->expects($this->once())->method('isCurrent')->will($this->returnValue(true));
$this->builder->setMatcher($matcher);
$menu->expects($this->exactly(2))->method('addChild');
$menu->expects($this->once())->method('setExtra')->with('type', $type);
$menu->expects($this->once())->method('getChildren')->will($this->returnValue($children));
$menu->expects($this->once())->method('removeChild');
$n = rand(1, 10);
$configMock = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Config\\UserConfigManager')->disableOriginalConstructor()->getMock();
$configMock->expects($this->once())->method('get')->with($this->equalTo('oro_navigation.maxItems'))->will($this->returnValue($n));
$this->manipulator->expects($this->once())->method('slice')->with($menu, 0, $n);
$this->builder->setOptions($configMock);
$this->builder->build($menu, [], $type);
}
示例3: testRemoveTracker
public function testRemoveTracker()
{
$tracker = $this->tracker();
$this->em->expects($this->once())->method('remove')->with($tracker);
$this->em->expects($this->once())->method('flush');
$this->repository->removeTracker($tracker);
}
示例4: testThrownException
public function testThrownException()
{
$this->em->expects($this->any())->method('find')->will($this->throwException(new \Doctrine\ORM\ORMException()));
$this->setExpectedException('SR\\Doctrine\\Exception\\ORMException');
$g = new StringUuid4PessimisticGenerator();
$g->generate($this->em, $this->entity);
}
示例5: testFixEntityAssociationFieldsEntity
/**
* @dataProvider valueDataProvider
* @param mixed $fieldValue
*/
public function testFixEntityAssociationFieldsEntity($fieldValue)
{
$entity = new \stdClass();
$entity->field = $fieldValue;
$mapping = array(array('fieldName' => 'field'));
if ($fieldValue instanceof ArrayCollection) {
$linkedEntity = $fieldValue->getIterator()->offsetGet(0);
} else {
$linkedEntity = $fieldValue;
}
$metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
$metadata->expects($this->once())->method('getAssociationMappings')->will($this->returnValue($mapping));
$metadata->expects($this->once())->method('getIdentifierValues')->with($linkedEntity)->will($this->returnValue('id'));
$this->entityManager->expects($this->exactly(2))->method('getClassMetadata')->with(get_class($entity))->will($this->returnValue($metadata));
$uow = $this->getMockBuilder('\\Doctrine\\ORM\\UnitOfWork')->disableOriginalConstructor()->getMock();
$uow->expects($this->once())->method('getEntityState')->with($linkedEntity)->will($this->returnValue(UnitOfWork::STATE_DETACHED));
$this->entityManager->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($uow));
$this->entityManager->expects($this->once())->method('find')->with(get_class($entity), 'id')->will($this->returnCallback(function () use($entity) {
$entity->reloaded = true;
return $entity;
}));
$this->fixer->fixEntityAssociationFields($entity, 0);
if ($fieldValue instanceof ArrayCollection) {
$this->assertTrue($entity->field->getIterator()->offsetGet(0)->reloaded);
} else {
$this->assertTrue($entity->field->reloaded);
}
}
示例6: testGetTree
public function testGetTree()
{
$userRepo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
$buRepo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
$this->em->expects($this->any())->method('getRepository')->will($this->returnValueMap([['Oro\\Bundle\\UserBundle\\Entity\\User', $userRepo], ['Oro\\Bundle\\OrganizationBundle\\Entity\\BusinessUnit', $buRepo]]));
list($users, $bUnits) = $this->getTestData();
$userRepo->expects($this->any())->method('findAll')->will($this->returnValue($users));
$qb = $this->getMockBuilder('\\Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
$query = $this->getMockBuilder('\\Doctrine\\ORM\\AbstractQuery')->setMethods(['setParameter', 'getArrayResult'])->disableOriginalConstructor()->getMockForAbstractClass();
$buRepo->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($qb));
$qb->expects($this->once())->method('select')->will($this->returnValue($qb));
$qb->expects($this->once())->method('getQuery')->will($this->returnValue($query));
$query->expects($this->once())->method('getArrayResult')->will($this->returnValue($bUnits));
$metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
$this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($metadata));
$metadata->expects($this->any())->method('getTableName')->will($this->returnValue('test'));
$connection = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock();
$this->em->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
$schemaManager = $this->getMockBuilder('Doctrine\\DBAL\\Schema\\MySqlSchemaManager')->disableOriginalConstructor()->getMock();
$connection->expects($this->any())->method('getSchemaManager')->will($this->returnValue($schemaManager));
$schemaManager->expects($this->any())->method('tablesExist')->with('test')->will($this->returnValue(true));
$this->treeProvider->warmUpCache();
/** @var OwnerTree $tree */
$tree = $this->treeProvider->getTree();
$this->assertEquals(1, $tree->getBusinessUnitOrganizationId(1));
$this->assertEquals([1], $tree->getUserOrganizationIds(1));
}
示例7: testProductShouldBeSuspendedAndFlushedWhenSuspendTheProduct
public function testProductShouldBeSuspendedAndFlushedWhenSuspendTheProduct()
{
$product = new Product('test');
$this->entityManager->expects(self::once())->method('persist')->with($product);
$this->entityManager->expects(self::once())->method('flush');
$this->productService->suspend($product);
}
示例8: testProcessGoodScenario
public function testProcessGoodScenario()
{
$testWebsiteId = 1;
$testStoreId = 2;
$testStoresArray = new \ArrayIterator([['website_id' => $testWebsiteId, 'store_id' => $testStoreId]]);
$settingBag = new ParameterBag(['website_id' => $testWebsiteId]);
$testData = [['id' => 1, 'originId' => 11], ['id' => 2, 'originId' => 22], ['id' => 3, 'originId' => 33]];
$testExistedCarts = [(object) ['entity_id' => 22]];
$repo = $this->getMockBuilder('OroCRM\\Bundle\\MagentoBundle\\Entity\\Repository\\CartRepository')->disableOriginalConstructor()->getMock();
$this->em->expects($this->any())->method('getRepository')->with('OroCRMMagentoBundle:Cart')->will($this->returnValue($repo));
$transport = $this->getMockBuilder('Oro\\Bundle\\IntegrationBundle\\Entity\\Transport')->setMethods(['getSettingsBag'])->getMockForAbstractClass();
$transport->expects($this->any())->method('getSettingsBag')->will($this->returnValue($settingBag));
$realTransport = $this->getMock('OroCRM\\Bundle\\MagentoBundle\\Provider\\Transport\\MagentoTransportInterface');
$realTransport->expects($this->once())->method('isSupportedExtensionVersion')->will($this->returnValue(true));
$realTransport->expects($this->once())->method('getStores')->will($this->returnValue($testStoresArray));
$this->helper->expects($this->once())->method('getTransport')->will($this->returnValue($realTransport));
$channel = new Channel();
$channel->setTransport($transport);
$realTransport->expects($this->at(3))->method('call')->with(SoapTransport::ACTION_ORO_CART_LIST, ['filters' => ['complex_filter' => [['key' => 'store_id', 'value' => ['key' => 'in', 'value' => $testStoreId]], ['key' => 'entity_id', 'value' => ['key' => 'in', 'value' => '11,22']]]], 'pager' => ['page' => 1, 'pageSize' => self::BATCH_SIZE]])->will($this->returnValue($testExistedCarts));
$realTransport->expects($this->at(4))->method('call')->with(SoapTransport::ACTION_ORO_CART_LIST, ['filters' => ['complex_filter' => [['key' => 'store_id', 'value' => ['key' => 'in', 'value' => $testStoreId]], ['key' => 'entity_id', 'value' => ['key' => 'in', 'value' => '33']]]], 'pager' => ['page' => 1, 'pageSize' => self::BATCH_SIZE]])->will($this->returnValue([]));
$repo->expects($this->once())->method('getCartsByChannelIdsIterator')->with($channel)->will($this->returnValue($testData));
$repo->expects($this->at(1))->method('markExpired')->with([1]);
$repo->expects($this->at(2))->method('markExpired')->with([3]);
$this->processor->process($channel);
}
示例9: setUp
/**
* Sets up a PostMetaManager instance.
*/
protected function setUp()
{
$this->entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
$this->repository = $this->getMockBuilder('Ekino\\WordpressBundle\\Repository\\PostMetaRepository')->disableOriginalConstructor()->getMock();
$this->entityManager->expects($this->any())->method('getRepository')->will($this->returnValue($this->repository));
$this->manager = new PostMetaManager($this->entityManager, 'Ekino\\WordpressBundle\\Entity\\PostMeta');
}
示例10: testIsApplicableOnEmailCampaign
/**
* @param EmailCampaign $emailCampaign
* @param Campaign $campaign
* @param bool $expected
* @dataProvider staticCampaignProvider
*/
public function testIsApplicableOnEmailCampaign($emailCampaign, $campaign, $expected)
{
$this->entityRepository->expects($this->any())->method('findOneBy')->will($this->returnValue($campaign));
$this->managerRegistry->expects($this->any())->method('getManager')->will($this->returnValue($this->entityManager));
$this->entityManager->expects($this->any())->method('getRepository')->will($this->returnValue($this->entityRepository));
$this->assertEquals($expected, $this->placeholderFilter->isApplicableOnEmailCampaign($emailCampaign));
}
示例11: setUp
/**
* Sets up a OptionManager instance.
*/
protected function setUp()
{
$this->entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
$this->repository = $this->getMockBuilder('Parenthesis\\WPBundle\\Repository\\OptionRepository')->disableOriginalConstructor()->getMock();
$this->entityManager->expects($this->any())->method('getRepository')->will($this->returnValue($this->repository));
$this->manager = new OptionManager($this->entityManager, 'Parenthesis\\WPBundle\\Entity\\Option');
}
示例12: testSchedule
public function testSchedule()
{
$testIntegrationType = 'testIntegrationType';
$testConnectorType = 'testConnectorType';
$testId = 22;
$integration = new Integration();
$integration->setType($testIntegrationType);
$integration->setEnabled(true);
$ref = new \ReflectionProperty(get_class($integration), 'id');
$ref->setAccessible(true);
$ref->setValue($integration, $testId);
$this->typesRegistry->addChannelType($testIntegrationType, new TestIntegrationType());
$this->typesRegistry->addConnectorType($testConnectorType, $testIntegrationType, new TestTwoWayConnector());
$that = $this;
$uow = $this->getMockBuilder('Doctrine\\ORM\\UnitOfWork')->disableOriginalConstructor()->getMock();
$this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($uow));
$metadataFactory = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadataFactory')->disableOriginalConstructor()->getMock();
$metadataFactory->expects($this->once())->method('getMetadataFor')->will($this->returnValue(new ClassMetadata('testEntity')));
$this->em->expects($this->once())->method('getMetadataFactory')->will($this->returnValue($metadataFactory));
$uow->expects($this->once())->method('persist')->with($this->isInstanceOf('JMS\\JobQueueBundle\\Entity\\Job'))->will($this->returnCallback(function (Job $job) use($that, $testId, $testConnectorType) {
$expectedArgs = ['--integration=' . $testId, sprintf('--connector=testConnectorType', $testConnectorType), '--params=a:0:{}'];
$that->assertEquals($expectedArgs, $job->getArgs());
}));
$uow->expects($this->once())->method('computeChangeSet');
$this->scheduler->schedule($integration, $testConnectorType, [], false);
}
示例13: setUp
protected function setUp()
{
$this->registry = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ManagerRegistry')->disableOriginalConstructor()->getMock();
$this->manager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
$this->registry->expects($this->any())->method('getManagerForClass')->with($this->objectClass)->will($this->returnValue($this->manager));
$this->repository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository', array('customQueryBuilderCreator', 'createQueryBuilder', 'find', 'findAll', 'findBy', 'findOneBy', 'getClassName'));
$this->manager->expects($this->any())->method('getRepository')->with($this->objectClass)->will($this->returnValue($this->repository));
}
示例14: setUp
public function setUp()
{
$this->processor = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Model\\WebSocket\\WebSocketSendProcessor')->disableOriginalConstructor()->getMock();
$this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
$this->uow = $this->getMockBuilder('Doctrine\\ORM\\UnitOfWork')->disableOriginalConstructor()->getMock();
$this->em->expects($this->any())->method('getUnitOfWork')->willReturn($this->uow);
$this->listener = new EmailUserListener($this->processor);
}
示例15: testIsApplicableOnMarketingList
/**
* @param null|StaticSegment $staticSegment
* @param bool $expected
* @dataProvider staticSegmentDataProvider
*/
public function testIsApplicableOnMarketingList($staticSegment, $expected)
{
$this->entityRepository->expects($this->once())->method('findOneBy')->will($this->returnValue($staticSegment));
$this->managerRegistry->expects($this->once())->method('getManager')->will($this->returnValue($this->entityManager));
$this->entityManager->expects($this->once())->method('getRepository')->will($this->returnValue($this->entityRepository));
$entity = new MarketingList();
$this->assertEquals($expected, $this->placeholderFilter->isApplicableOnMarketingList($entity));
}