Skip to content

Commit

Permalink
More tests for GQL params
Browse files Browse the repository at this point in the history
  • Loading branch information
twalder-docnet committed Jun 12, 2015
1 parent e762716 commit 8929257
Showing 1 changed file with 87 additions and 9 deletions.
96 changes: 87 additions & 9 deletions tests/ProtoBufGqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,103 @@ public function testFetchOneStringParam()
}

/**
* @todo Fetch with an Integer parameter
* Fetch all
*/
public function testFetchAllNoParams()
{
$str_gql = "SELECT * FROM Kind";
$obj_request = new \google\appengine\datastore\v4\RunQueryRequest();
$obj_request->mutableReadOptions();
$obj_partition = $obj_request->mutablePartitionId();
$obj_partition->setDatasetId('Dataset');
$obj_gql_query = $obj_request->mutableGqlQuery();
$obj_gql_query->setAllowLiteral(TRUE);
$obj_gql_query->setQueryString($str_gql);

/**
* @todo Fetch with a DateTime parameter
*/
$this->apiProxyMock->expectCall('datastore_v4', 'RunQuery', $obj_request, new \google\appengine\datastore\v4\RunQueryResponse());

/**
* @todo Fetch with a root GDS\Entity parameter
*/
$obj_store = $this->createBasicStore();
$obj_result = $obj_store->fetchAll($str_gql);

$this->assertEquals($obj_result, []);
$this->apiProxyMock->verify();
}

/**
* @todo Fetch with an GDS\Entity parameter (with ancestors)
* Fetch with a multiple mixed type parameters
*/
public function testFetchOneMultiParam()
{
$str_gql = "SELECT * FROM Kind WHERE property1 = @param1 AND property2 = @param2 AND property3 = @param3";
$obj_request = new \google\appengine\datastore\v4\RunQueryRequest();
$obj_request->mutableReadOptions();
$obj_partition = $obj_request->mutablePartitionId();
$obj_partition->setDatasetId('Dataset');

$obj_gql_query = $obj_request->mutableGqlQuery();
$obj_gql_query->setAllowLiteral(TRUE);
$obj_gql_query->setQueryString($str_gql . " LIMIT 1");

$obj_arg1 = $obj_gql_query->addNameArg();
$obj_arg1->setName('param1');
$obj_arg1->mutableValue()->setIntegerValue(123);

$obj_arg2 = $obj_gql_query->addNameArg();
$obj_arg2->setName('param2');
$obj_arg2->mutableValue()->setTimestampMicrosecondsValue(286965000000000);

$obj_arg3 = $obj_gql_query->addNameArg();
$obj_arg3->setName('param3');
$obj_arg3->mutableValue()->setStringValue('test3');

$this->apiProxyMock->expectCall('datastore_v4', 'RunQuery', $obj_request, new \google\appengine\datastore\v4\RunQueryResponse());

$obj_store = $this->createBasicStore();
$obj_result = $obj_store->fetchOne($str_gql, [
'param1' => 123,
'param2' => new DateTime('1979-02-04 08:30:00'),
'param3' => 'test3'
]);

$this->assertEquals($obj_result, NULL);
$this->apiProxyMock->verify();
}

/**
* @todo Fetch with a multiple mixed type parameters
* Fetch with a root GDS\Entity parameter
*/
public function testFetchOneEntityParam()
{
$str_gql = "SELECT * FROM Kind WHERE property = @param";
$obj_request = new \google\appengine\datastore\v4\RunQueryRequest();
$obj_request->mutableReadOptions();
$obj_partition = $obj_request->mutablePartitionId();
$obj_partition->setDatasetId('Dataset');

$obj_gql_query = $obj_request->mutableGqlQuery();
$obj_gql_query->setAllowLiteral(TRUE);
$obj_gql_query->setQueryString($str_gql . " LIMIT 1");

$obj_arg = $obj_gql_query->addNameArg();
$obj_arg->setName('param');
$obj_key = $obj_arg->mutableValue()->mutableKeyValue();
$obj_kpe = $obj_key->addPathElement();
$obj_kpe->setKind('Book');
$obj_kpe->setName('test-key-name-here');

$this->apiProxyMock->expectCall('datastore_v4', 'RunQuery', $obj_request, new \google\appengine\datastore\v4\RunQueryResponse());

$obj_entity = (new GDS\Entity())->setKind('Book')->setKeyName('test-key-name-here');

$obj_store = $this->createBasicStore();
$obj_result = $obj_store->fetchOne($str_gql, ['param' => $obj_entity]);

$this->assertEquals($obj_result, NULL);
$this->apiProxyMock->verify();
}

/**
* @todo Fetch with an GDS\Entity parameter (with ancestors)
*/

}

0 comments on commit 8929257

Please sign in to comment.