本文整理汇总了PHP中Doctrine\ORM\QueryBuilder::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::expects方法的具体用法?PHP QueryBuilder::expects怎么用?PHP QueryBuilder::expects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder::expects方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
$mockPersistenceManager = $this->createMock(PersistenceManagerInterface::class);
$this->mockQuery = $this->getMockBuilder(Query::class)->disableOriginalConstructor()->getMock();
$this->mockQueryBuilder = $this->getMockBuilder(QueryBuilder::class)->disableOriginalConstructor()->getMock();
$this->mockQueryBuilder->expects($this->any())->method('getQuery')->will($this->returnValue($this->mockQuery));
$this->nodeDataRepository = $this->getMockBuilder(NodeDataRepository::class)->setMethods(array('getNodeDataForParentAndNodeType', 'filterNodesOverlaidInBaseWorkspace', 'getNodeTypeFilterConstraintsForDql', 'createQueryBuilder', 'addPathConstraintToQueryBuilder', 'filterNodeDataByBestMatchInContext'))->getMock();
$this->nodeDataRepository->expects($this->any())->method('filterNodesOverlaidInBaseWorkspace')->will($this->returnCallback(function (array $foundNodes, Workspace $baseWorkspace, $dimensions) {
return $foundNodes;
}));
$this->nodeDataRepository->expects($this->any())->method('createQueryBuilder')->will($this->returnValue($this->mockQueryBuilder));
$this->nodeDataRepository->expects($this->any())->method('filterNodeDataByBestMatchInContext')->will($this->returnArgument(0));
// The repository needs an explicit entity class name because of the generated mock class name
$this->inject($this->nodeDataRepository, 'entityClassName', NodeData::class);
$this->inject($this->nodeDataRepository, 'persistenceManager', $mockPersistenceManager);
}
示例2: thatFilters
/**
* @test
*/
public function thatFilters()
{
$a = new EntityStub();
$b = new EntityStub();
$a->name = "DUMMY_NAME";
$a->id = 1;
$b->name = "NOT_DUMMY_NAME";
$b->id = 2;
$entities = array($a, $b);
$pagingConfig = new FilterPagingProperties();
$conditions = array(array('name', 'eq', 'DUMMY_NAME'));
$whereExpr = new \Doctrine\ORM\Query\Expr\Comparison('e.name', 'eq', "'DUMMY_NAME'");
$this->em->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($this->queryBuilder));
$this->queryBuilder->expects($this->once())->method('select')->with($this->equalTo('e'))->will($this->returnValue($this->queryBuilder));
$this->queryBuilder->expects($this->once())->method('from')->with($this->equalTo($this->classMetadata->name), $this->equalTo('e'))->will($this->returnValue($this->queryBuilder));
$this->queryBuilder->expects($this->atLeastOnce())->method('andWhere')->with($this->equalTo($whereExpr))->will($this->returnValue($this->queryBuilder));
$this->queryBuilder->expects($this->once())->method('addOrderBy')->with($this->equalTo('e.id'), $this->equalTo($pagingConfig->getOrder()))->will($this->returnValue($this->queryBuilder));
$this->queryBuilder->expects($this->once())->method('setFirstResult')->with($this->equalTo(0))->will($this->returnValue($this->queryBuilder));
$this->queryBuilder->expects($this->once())->method('setMaxResults')->with($this->equalTo($pagingConfig->getLimit()))->will($this->returnValue($this->queryBuilder));
$this->queryBuilder->expects($this->once())->method('getQuery')->will($this->returnValue($this->filterQuery));
$this->queryBuilder->expects($this->any())->method('expr')->will($this->returnValue($this->expressionBuilder));
$this->em->expects($this->any())->method('getExpressionBuilder')->will($this->returnValue($this->expressionBuilder));
$this->expressionBuilder->expects($this->atLeastOnce())->method('literal')->with($this->equalTo('DUMMY_NAME'))->will($this->returnValue("'DUMMY_NAME'"));
$this->expressionBuilder->expects($this->atLeastOnce())->method('eq')->with($this->equalTo('e.name'), $this->equalTo("'DUMMY_NAME'"))->will($this->returnValue($whereExpr));
$this->em->expects($this->atLeastOnce())->method('newHydrator')->with($this->equalTo(Query::HYDRATE_OBJECT))->will($this->returnValue($this->objectHydrator));
$this->objectHydrator->expects($this->atLeastOnce())->method('hydrateAll')->will($this->returnValue(array($a)));
$filteredEntities = $this->repository->filter($conditions, $pagingConfig);
$this->assertNotNull($filteredEntities);
$this->assertTrue(is_array($filteredEntities));
$this->assertNotEmpty($filteredEntities);
$this->assertEquals($a, $filteredEntities[0]);
}
示例3: testCreateDataSourceWithAllOption
public function testCreateDataSourceWithAllOption()
{
$this->queryBuilder->expects($this->once())->method('getQuery')->will($this->returnValue($query = $this->createQueryMock()));
$query->expects($this->once())->method('getResult')->will($this->returnValue($values = [new \stdClass()]));
$dataSource = $this->builder->createDataSource(['all' => true]);
$this->assertInstanceOf(ArrayDataSource::class, $dataSource);
$this->assertSame($values, iterator_to_array($dataSource));
}
示例4: setSearchExpects
protected function setSearchExpects()
{
$this->entityRepository->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($this->queryBuilder));
$this->queryBuilder->expects($this->once())->method('where')->will($this->returnSelf());
$this->queryBuilder->expects($this->exactly(2))->method('andWhere')->will($this->returnSelf());
$this->queryBuilder->expects($this->exactly(3))->method('setParameter')->will($this->returnSelf());
$this->queryBuilder->expects($this->exactly(2))->method('addOrderBy')->will($this->returnSelf());
$this->queryBuilder->expects($this->any())->method('expr')->will($this->returnValue($this->expr));
$this->aclHelper->expects($this->once())->method('apply')->will($this->returnValue($this->queryBuilder));
}
示例5: getQueryBuilder
/**
* @return QueryBuilder
*/
public function getQueryBuilder()
{
$testChoiceEntities = $this->getTestChoiceEntities($this->testChoices);
if (!$this->queryBuilder) {
$query = $this->getMockBuilder('Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(array('execute', 'setHint'))->getMockForAbstractClass();
$query->expects($this->any())->method('execute')->will($this->returnValue($testChoiceEntities));
$this->queryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->setMethods(array('getQuery'))->getMock();
$this->queryBuilder->expects($this->any())->method('getQuery')->will($this->returnValue($query));
}
return $this->queryBuilder;
}
示例6: testSearch
/**
* @test
*/
public function testSearch()
{
$a = new EntityStub();
$b = new EntityStub();
$a->name = "DUMMY_NAME";
$a->status = "new";
$a->id = 1;
$b->name = "NOT_DUMMY_NAME";
$b->status = "closed";
$b->id = 2;
$entities = array($a, $b);
$pagingConfig = new FilterPagingProperties();
$querySearch = 'NAM';
$conditions = array(array('status', 'eq', 'new'));
$this->em->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($this->queryBuilder));
$this->queryBuilder->expects($this->once())->method('select')->with($this->equalTo('e'))->will($this->returnValue($this->queryBuilder));
$this->queryBuilder->expects($this->once())->method('from')->with($this->equalTo($this->classMetadata->name), $this->equalTo('e'))->will($this->returnValue($this->queryBuilder));
$whereExpr = new \Doctrine\ORM\Query\Expr\Comparison('e.status', 'eq', 'new');
$likeExprSubject = new \Doctrine\ORM\Query\Expr\Comparison('e.subject', 'like', '%NAM%');
$likeExprDescription = new \Doctrine\ORM\Query\Expr\Comparison('e.description', 'like', '%NAM%');
$whereExprOrx = new \Doctrine\ORM\Query\Expr\Orx($likeExprSubject, $likeExprDescription);
$this->queryBuilder->expects($this->atLeastOnce())->method('andWhere')->with($this->logicalOr($this->equalTo($whereExpr), $this->equalTo($whereExprOrx)))->will($this->returnValue($this->queryBuilder));
$this->queryBuilder->expects($this->once())->method('addOrderBy')->with($this->equalTo('e.id'), $this->equalTo($pagingConfig->getOrder()))->will($this->returnValue($this->queryBuilder));
$this->queryBuilder->expects($this->once())->method('setFirstResult')->with($this->equalTo(0))->will($this->returnValue($this->queryBuilder));
$this->queryBuilder->expects($this->once())->method('setMaxResults')->with($this->equalTo($pagingConfig->getLimit()))->will($this->returnValue($this->queryBuilder));
$this->queryBuilder->expects($this->once())->method('getQuery')->will($this->returnValue($this->searchQuery));
$this->queryBuilder->expects($this->any())->method('expr')->will($this->returnValue($this->expressionBuilder));
$this->em->expects($this->any())->method('getExpressionBuilder')->will($this->returnValue($this->expressionBuilder));
$this->expressionBuilder->expects($this->atLeast(2))->method('literal')->with($this->logicalOr($this->equalTo('new'), $this->equalTo('%' . $querySearch . '%')))->will($this->returnCallback(array($this, 'literalCallback')));
$this->expressionBuilder->expects($this->atLeastOnce())->method('eq')->with($this->equalTo('e.status'), $this->equalTo('new'))->will($this->returnValue($whereExpr));
$this->expressionBuilder->expects($this->atLeastOnce())->method('Orx')->with($this->anything(), $this->anything())->will($this->returnValue($whereExprOrx));
$this->em->expects($this->atLeastOnce())->method('newHydrator')->with($this->equalTo(Query::HYDRATE_OBJECT))->will($this->returnValue($this->objectHydrator));
$this->objectHydrator->expects($this->atLeastOnce())->method('hydrateAll')->will($this->returnValue(array($a)));
$searchedEntities = $this->repository->search($querySearch, $conditions, $pagingConfig);
$this->assertNotNull($searchedEntities);
$this->assertTrue(is_array($searchedEntities));
$this->assertNotEmpty($searchedEntities);
$this->assertEquals($a, $searchedEntities[0]);
}
示例7: setUp
public function setUp()
{
$this->queryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
$this->queryBuilder->expects($this->any())->method('setParameter')->willReturnSelf();
}