我正在使用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 中找不到它。