Google\Cloud\Tests\Datastore\OperationTest::testRunQueryPaged PHP Method

testRunQueryPaged() public method

public testRunQueryPaged ( )
    public function testRunQueryPaged()
    {
        $queryResult = json_decode(file_get_contents(__DIR__ . '/../fixtures/datastore/query-results.json'), true);
        $this->connection->runQuery(Argument::type('array'))->will(function ($args, $mock) use($queryResult) {
            // The 2nd call will return the 2nd page of results!
            $mock->runQuery(Argument::type('array'))->willReturn($queryResult['paged'][1]);
            return $queryResult['paged'][0];
        });
        $this->operation->setConnection($this->connection->reveal());
        $q = $this->prophesize(QueryInterface::class);
        $q->queryKey()->shouldBeCalled()->willReturn('query');
        $q->queryObject()->shouldBeCalled()->willReturn([]);
        $q->canPaginate()->willReturn(true);
        $q->start(Argument::any())->willReturn(null);
        $res = $this->operation->runQuery($q->reveal());
        $this->assertInstanceOf(\Generator::class, $res);
        $arr = iterator_to_array($res);
        $this->assertEquals(count($arr), 3);
        $this->assertInstanceOf(Entity::class, $arr[0]);
    }