How should I prophesy the sort method?

163 Views Asked by At

I am using the DoctrineMongoDBBundle and I am not sure how to prophesy the sort method.

Source

$qb = $dm->createQueryBuilder('Article')
->sort('createdAt', 'desc');

My code is:

UserRepository - Method All

public function all(array $input = null)
    {
    $user = UserEntity::class;

    $all = $this->dm->createQueryBuilder($user);

    $search = $all->sort(['name' => 'asc'])
            ->getQuery();

        return $search;
    }

UserRepositoryTest - prophecy

public function testSortingResults()
{
    $output = [
        'name' => 'John',
        'email' => '[email protected]',
        '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);
}

The error is always this

Prophecy\Exception\Doubler\MethodNotFoundException: Method Double\Doctrine\ORM\QueryBuilder\P2::sort() is not defined.

I do not understand how to test SORT, because it is not found in QueryBuilder.

0

There are 0 best solutions below