我正在使用DoctrineMongoDBBundle,但不确定如何对排序方法进行预言。
$qb = $dm->createQueryBuilder('Article')
->sort('createdAt', 'desc');
我的代码是:
UserRepository-方法全部
public function all(array $input = null)
{
$user = UserEntity::class;
$all = $this->dm->createQueryBuilder($user);
$search = $all->sort(['name' => 'asc'])
->getQuery();
return $search;
}
UserRepositoryTest-预言
public function testSortingResults()
{
$output = [
'name' => 'John',
'email' => 'john@email.com',
'phone' => '89564789547',
];
$document = $this->prophesize(DocumentManager::class);
$queryBuilder = $this->prophesize(QueryBuilder::class);
$queryBuilder->sort()->willReturn($output)->shouldBeCalled();
$queryBuilder->getQuery()->willReturn($output)->shouldBeCalled();
$document->createQueryBuilder(UsuarioEntidade::class)->willReturn($queryBuilder)->shouldBeCalled();
$repository = new UserRepository($document->reveal());
$all = $repository->all();
$this->assertNotNull($all);
$this->assertEquals($output, $all);
}
错误总是这样
Prophecy \ Exception \ Doubler \ MethodNotFoundException:方法
Double\Doctrine\ORM\QueryBuilder\P2::sort()
未定义。
我不知道如何测试SORT,因为在QueryBuilder中找不到它。