我应该如何预言排序方法?

时间:2018-10-03 14:35:50

标签: php doctrine-mongodb prophecy

我正在使用DoctrineMongoDBBundle,但不确定如何对排序方法进行预言。

Source

$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中找不到它。

0 个答案:

没有答案