Skip to content

Commit

Permalink
More tests for string list mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
twalder-docnet committed Jun 17, 2015
1 parent d91ab13 commit 1342f42
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 3 deletions.
45 changes: 43 additions & 2 deletions tests/ProtoBufCreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public function testUpsertSchemaOneAutoId()

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

$_SERVER[''];
$obj_schema = (new \GDS\Schema('Book'))
->addString('title', FALSE)
->addDatetime('published', FALSE);
Expand Down Expand Up @@ -255,7 +254,49 @@ public function testUpsertEntityAncestorOneLevel()
*/

/**
* @todo Create with string list
* Insert with a String List
*
* @expectedException Exception
* @expectedExceptionMessage Mismatch count of requested & returned Auto IDs
*/
public function testUpsertStringList()
{
$obj_request = new \google\appengine\datastore\v4\CommitRequest();
$obj_request->setMode(\google\appengine\datastore\v4\CommitRequest\Mode::NON_TRANSACTIONAL);
$obj_mutation = $obj_request->mutableDeprecatedMutation();

$obj_entity = $obj_mutation->addInsertAutoId();

$obj_result_key = $obj_entity->mutableKey();
$obj_partition = $obj_result_key->mutablePartitionId();
$obj_partition->setDatasetId('Dataset');
$obj_result_kpe = $obj_result_key->addPathElement();
$obj_result_kpe->setKind('Film');

$obj_result_property = $obj_entity->addProperty();
$obj_result_property->setName('director');
$obj_result_property->mutableValue()->setStringValue('Robert Zemeckis')->setIndexed(FALSE);

$obj_val2 = $obj_entity->addProperty()->setName('dedications')->mutableValue();
$obj_val2->addListValue()->setStringValue('Marty McFly')->setIndexed(FALSE);
$obj_val2->addListValue()->setStringValue('Emmett Brown')->setIndexed(FALSE);

$obj_val3 = $obj_entity->addProperty()->setName('fans')->mutableValue();
$obj_val3->addListValue()->setStringValue('Tom Walder')->setIndexed(TRUE);

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

$obj_schema = (new \GDS\Schema('Film'))
->addString('director', FALSE)
->addStringList('dedications', FALSE);
$obj_gateway = new GDS\Gateway\ProtoBuf('Dataset');
$obj_store = new GDS\Store($obj_schema, $obj_gateway);
$obj_store->upsert($obj_store->createEntity([
'director' => 'Robert Zemeckis',
'dedications' => ['Marty McFly', 'Emmett Brown'],
'fans' => ['Tom Walder']
]));
$this->apiProxyMock->verify();
}

}
41 changes: 40 additions & 1 deletion tests/ProtoBufFetchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,45 @@ public function testFetchByIdWithVariantSchemaResult()
*/

/**
* @todo Fetch with string list
* Fetch with string list
*/
public function testFetchWithStringListResult()
{

$obj_response = new \google\appengine\datastore\v4\LookupResponse();
$obj_found = $obj_response->addFound();

$obj_entity = $obj_found->mutableEntity();
$obj_result_key = $obj_entity->mutableKey();
$obj_result_kpe = $obj_result_key->addPathElement();
$obj_result_kpe->setKind('Book');
$obj_result_kpe->setId(123456789);

$obj_result_property = $obj_entity->addProperty();
$obj_result_property->setName('director');
$obj_val = $obj_result_property->mutableValue();
$obj_val->setStringValue('Robert Zemeckis');

$obj_result_property2 = $obj_entity->addProperty();
$obj_result_property2->setName('dedications');
$obj_val2 = $obj_result_property2->mutableValue();
$obj_val2->addListValue()->setStringValue('Marty McFly');
$obj_val2->addListValue()->setStringValue('Emmett Brown');

$this->apiProxyMock->expectCall('datastore_v4', 'Lookup', $this->getBasicBookByIdRequest(), $obj_response);

$obj_gateway = new GDS\Gateway\ProtoBuf('Dataset');
$obj_store = new GDS\Store('Book', $obj_gateway);
$obj_result = $obj_store->fetchById(123456789);

$this->assertInstanceOf('\\GDS\\Entity', $obj_result);
$this->assertEquals(2, count($obj_result->getData()));
$this->assertEquals('Book', $obj_result->getKind());
$this->assertEquals(123456789, $obj_result->getKeyId());
$this->assertEquals('Robert Zemeckis', $obj_result->director);
$this->assertEquals(['Marty McFly', 'Emmett Brown'] ,$obj_result->dedications);

$this->apiProxyMock->verify();
}

}

0 comments on commit 1342f42

Please sign in to comment.