Example #1
0
 /**
  * Fetch Page with cursor offset from historical value, using 'default query'
  */
 public function testFetchPageHistoricalCursor()
 {
     $obj_request = $this->getBasicFetchRequest();
     $obj_gql_query = $obj_request->mutableGqlQuery();
     $obj_gql_query->setAllowLiteral(TRUE);
     $obj_gql_query->setQueryString("SELECT * FROM `Person` ORDER BY __key__ ASC LIMIT @intPageSize OFFSET @startCursor");
     $obj_arg = $obj_gql_query->addNameArg();
     $obj_arg->setName('intPageSize');
     $obj_arg->mutableValue()->setIntegerValue(11);
     $obj_arg_offset = $obj_gql_query->addNameArg();
     $obj_arg_offset->setName('startCursor');
     $obj_arg_offset->setCursor('some-historical-cursor');
     $this->apiProxyMock->expectCall('datastore_v4', 'RunQuery', $obj_request, new \google\appengine\datastore\v4\RunQueryResponse());
     $obj_gateway = new GDS\Gateway\ProtoBuf('Dataset');
     $obj_schema = (new \GDS\Schema('Person'))->addString('name')->addInteger('age');
     $obj_store = new GDS\Store($obj_schema, $obj_gateway);
     $obj_store->setCursor('some-historical-cursor');
     $arr_result = $obj_store->fetchPage(11);
     $this->assertEquals($arr_result, []);
     $this->apiProxyMock->verify();
 }
Example #2
0
 /**
  * Test extraction of end cursors
  */
 public function testEndCursorExtract()
 {
     $str_end_cursor = 'gh3iu4reirh23j4ertiguhn34jetrihue';
     $obj_http = $this->initTestHttpClient('https://datastore.googleapis.com/v1/projects/DatasetTest:runQuery', ['json' => (object) ['gqlQuery' => (object) ['allowLiterals' => true, 'queryString' => 'SELECT * FROM `Test` ORDER BY __key__ ASC LIMIT @intPageSize ', 'namedBindings' => (object) ['intPageSize' => (object) ['value' => (object) ['integerValue' => 50]]]], 'partitionId' => (object) ['projectId' => self::TEST_PROJECT]]], ['batch' => (object) ['entityResultType' => 'FULL', 'entityResults' => [(object) ['entity' => (object) ['key' => (object) ['path' => [(object) ['kind' => 'Test', 'id' => '123123123123']]], 'properties' => (object) ['name' => (object) ['excludeFromIndexes' => false, 'stringValue' => 'Tom'], 'age' => (object) ['excludeFromIndexes' => false, 'integerValue' => 37]]], 'version' => '123', 'cursor' => 'gfuh37f86gyu23']], 'endCursor' => $str_end_cursor]]);
     $obj_gateway = $this->initTestGateway()->setHttpClient($obj_http);
     $obj_store = new \GDS\Store('Test', $obj_gateway);
     $arr_ents = $obj_store->fetchPage(50);
     $this->assertTrue(is_array($arr_ents));
     // End cursor?
     $this->assertEquals($str_end_cursor, $obj_store->getCursor());
     $this->validateHttpClient($obj_http);
 }