/** * Test Fetch With Ancestors */ public function testFetchWithAncestors() { $obj_gateway = new GDS\Gateway\GoogleAPIClient($this->setupTestClient(), 'Dataset'); $obj_store = new \GDS\Store('Person', $obj_gateway); $this->expectRequest('https://www.googleapis.com/datastore/v1beta2/datasets/Dataset/runQuery', '{"gqlQuery":{"allowLiteral":true,"queryString":"SELECT * FROM Person LIMIT @intPageSize ","nameArgs":[{"name":"intPageSize","value":{"integerValue":1}}]}}', '{"batch": {"entityResultType": "FULL","entityResults": [{"entity": {"key":{"partitionId": {"datasetId": "Dataset"},"path":[{"kind":"Person","name":"Johnny"},{"kind":"Person","id": "4804129360707584"}]},"properties":{"name":{"indexed":true,"stringValue":"Tom"},"age":{"indexed":true,"integerValue":36},"dob":{"dateTimeValue":"1979-02-04T08:30:00+00:00","indexed":true},"weight":{"doubleValue":94.5,"indexed":true},"likes_php":{"booleanValue":true,"indexed":true},"friends":{"listValue":[{"indexed":true,"stringValue":"Tom"},{"indexed":true,"stringValue":"Dick"},{"indexed":true,"stringValue":"Harry"}]}}}}],"endCursor": "CiQSHmoJc35waHAtZ2RzchELEgRCb29rGICAgMDIqsQIDBgAIAA=","moreResults": "MORE_RESULTS_AFTER_LIMIT","skippedResults": null}}'); $arr_result = $obj_store->query("SELECT * FROM Person")->fetchPage(1); $this->assertTrue(is_array($arr_result)); $this->assertEquals(1, count($arr_result)); $obj_result = $arr_result[0]; $this->assertInstanceOf('\\GDS\\Entity', $obj_result); $this->assertEquals('4804129360707584', $obj_result->getKeyId()); $this->assertEquals([['kind' => 'Person', 'id' => null, 'name' => 'Johnny']], $obj_result->getAncestry()); $this->assertEquals('CiQSHmoJc35waHAtZ2RzchELEgRCb29rGICAgMDIqsQIDBgAIAA=', $obj_store->getCursor()); }
/** * 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); }