Esempio n. 1
0
<?php

/**
 * Create a single record in GDS
 *
 * @author Tom Walder <*****@*****.**>
 */
require_once 'boilerplate.php';
$obj_person_schema = (new GDS\Schema('Person'))->addString('name')->addString('description');
$obj_store = new GDS\Store($obj_person_schema, $obj_gateway);
// Create the parent
$obj_john = new \GDS\Entity();
$obj_john->name = 'John Smiths';
$obj_john->description = 'A parent';
$obj_john->setKeyName('*****@*****.**');
$obj_store->upsert($obj_john);
$obj_stored_parent = $obj_store->fetchOne("SELECT * FROM Person WHERE __key__ = KEY(Person, '*****@*****.**')");
// Create a child
$obj_jane = new \GDS\Entity();
$obj_jane->name = 'Jane Smiths';
$obj_jane->description = 'A child';
$obj_jane->setKeyName('*****@*****.**');
$obj_jane->setAncestry($obj_stored_parent);
$obj_store->upsert($obj_jane);
 /**
  * Insert One with Parent
  *
  * @expectedException        Exception
  * @expectedExceptionMessage Mismatch count of requested & returned Auto IDs
  */
 public function testUpsertEntityAncestorOneLevel()
 {
     $this->apiProxyMock->expectCall('datastore_v4', 'Commit', $this->getUpsertRequestWithBookAndAuthor(), new \google\appengine\datastore\v4\CommitResponse());
     $obj_will = new GDS\Entity();
     $obj_will->setKind('Author');
     $obj_will->setKeyName('WilliamShakespeare');
     $obj_store = $this->createBasicStore();
     $obj_book = $obj_store->createEntity(['nickname' => 'Romeo']);
     $obj_book->setAncestry($obj_will);
     $obj_store->upsert($obj_book);
     $this->apiProxyMock->verify();
 }