Beispiel #1
0
 /**
  * Validate getters and setters for Ancestry
  */
 public function testAncestry()
 {
     $obj_entity1 = new GDS\Entity();
     $obj_entity1->setKind('Testing')->setKeyId(123456);
     $obj_entity2 = new GDS\Entity();
     $obj_entity2->setKind('Testing')->setKeyName('testing');
     $obj_entity2->setAncestry($obj_entity1);
     $this->assertEquals($obj_entity2->getAncestry(), $obj_entity1);
 }
 /**
  * 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();
 }
 /**
  * Create with 2+ Ancestors (from array)
  */
 public function testAncestryFromArray()
 {
     $obj_schema = (new \GDS\Schema('Child'))->addString('name', true);
     $obj_mapper = new \GDS\Mapper\ProtoBuf();
     $obj_mapper->setSchema($obj_schema);
     $obj_gds_child = new \GDS\Entity();
     $obj_gds_child->setKind('Child');
     $obj_gds_child->name = 'Son';
     $obj_gds_child->setAncestry([['kind' => 'GrandParent', 'id' => '123456781'], ['kind' => 'Parent', 'id' => '123456782']]);
     $obj_target_ent = new \google\appengine\datastore\v4\Entity();
     $obj_mapper->mapToGoogle($obj_gds_child, $obj_target_ent);
     /** @var \google\appengine\datastore\v4\Key\PathElement[] $arr_path */
     $arr_path = $obj_target_ent->getKey()->getPathElementList();
     $obj_path_first = $arr_path[0];
     $obj_path_second = $arr_path[1];
     $obj_path_last = $arr_path[2];
     $this->assertEquals('GrandParent', $obj_path_first->getKind());
     $this->assertEquals('123456781', $obj_path_first->getId());
     $this->assertEquals('Parent', $obj_path_second->getKind());
     $this->assertEquals('123456782', $obj_path_second->getId());
     $this->assertEquals('Child', $obj_path_last->getKind());
 }
Beispiel #4
0
 /**
  * Tests 2 tiers of ancestry, based on array
  */
 public function testAncestryFromArray()
 {
     $obj_schema = (new \GDS\Schema('Child'))->addString('name', true);
     $obj_mapper = new \GDS\Mapper\RESTv1();
     $obj_mapper->setSchema($obj_schema);
     $obj_gds_child = new \GDS\Entity();
     $obj_gds_child->setKind('Child');
     $obj_gds_child->name = 'Son';
     $obj_gds_child->setAncestry([['kind' => 'GrandParent', 'id' => '123456781'], ['kind' => 'Parent', 'id' => '123456782']]);
     $obj_rest_entity = $obj_mapper->mapToGoogle($obj_gds_child);
     $this->assertObjectHasAttribute('name', $obj_rest_entity->properties);
     $this->assertObjectHasAttribute('stringValue', $obj_rest_entity->properties->name);
     $this->assertEquals('Son', $obj_rest_entity->properties->name->stringValue);
     $this->assertObjectHasAttribute('key', $obj_rest_entity);
     $this->assertObjectHasAttribute('path', $obj_rest_entity->key);
     $this->assertTrue(is_array($obj_rest_entity->key->path));
     $this->assertEquals(3, count($obj_rest_entity->key->path));
     $obj_path_first = $obj_rest_entity->key->path[0];
     $obj_path_second = $obj_rest_entity->key->path[1];
     $obj_path_last = $obj_rest_entity->key->path[2];
     $this->assertObjectHasAttribute('kind', $obj_path_first);
     $this->assertObjectHasAttribute('id', $obj_path_first);
     $this->assertObjectNotHasAttribute('name', $obj_path_first);
     $this->assertEquals('GrandParent', $obj_path_first->kind);
     $this->assertEquals('123456781', $obj_path_first->id);
     $this->assertObjectHasAttribute('kind', $obj_path_second);
     $this->assertObjectHasAttribute('id', $obj_path_second);
     $this->assertObjectNotHasAttribute('name', $obj_path_second);
     $this->assertEquals('Parent', $obj_path_second->kind);
     $this->assertEquals('123456782', $obj_path_second->id);
     $this->assertObjectHasAttribute('kind', $obj_path_last);
     $this->assertObjectNotHasAttribute('id', $obj_path_last);
     $this->assertObjectNotHasAttribute('name', $obj_path_last);
     $this->assertEquals('Child', $obj_path_last->kind);
 }