/**
  * Start transaction
  */
 public function testBeginTransactionBasic()
 {
     $obj_request = new \google\appengine\datastore\v4\BeginTransactionRequest();
     $obj_response = new \google\appengine\datastore\v4\BeginTransactionResponse();
     $obj_response->setTransaction('test-txn-ref-123');
     $this->apiProxyMock->expectCall('datastore_v4', 'BeginTransaction', $obj_request, $obj_response);
     $_SERVER['APPLICATION_ID'] = 'DatasetTest';
     $obj_gateway = $this->getMockBuilder('\\GDS\\Gateway\\ProtoBuf')->setMethods(['withTransaction', 'fetchById'])->getMock();
     $obj_gateway->expects($this->once())->method('withTransaction')->with($this->equalTo('test-txn-ref-123'))->willReturn($obj_gateway);
     $obj_store = new GDS\Store('Book', $obj_gateway);
     $obj_store->beginTransaction();
     $obj_store->fetchById('123456');
     $this->apiProxyMock->verify();
 }
 /**
  * Test Failure on cross-group transactions
  *
  * @expectedException        Exception
  * @expectedExceptionMessage Cross group transactions not supported over JSON API
  */
 public function testFailCrossGroup()
 {
     $obj_gateway = new GDS\Gateway\GoogleAPIClient($this->setupTestClient(), 'Dataset');
     $obj_store = new \GDS\Store('Film', $obj_gateway);
     $obj_store->beginTransaction(TRUE);
 }
Example #3
0
 /**
  * Test transactional entity fetch
  */
 public function testTxnFetch()
 {
     // First begin the transaction
     $str_txn_ref = 'ghei34g498jhegijv0894hiwgerhiugjreiugh';
     $obj_http = $this->initTestHttpClient('https://datastore.googleapis.com/v1/projects/DatasetTest:beginTransaction', [], ['transaction' => $str_txn_ref]);
     /** @var \GDS\Gateway\RESTv1 $obj_gateway */
     $obj_gateway = $this->initTestGateway()->setHttpClient($obj_http);
     $obj_store = new \GDS\Store('Test', $obj_gateway);
     $obj_store->beginTransaction();
     $this->validateHttpClient($obj_http);
     // Now set up the transactional fetch
     $str_id = '1263751723';
     $obj_http = $this->initTestHttpClient('https://datastore.googleapis.com/v1/projects/DatasetTest:lookup', ['json' => (object) ['readOptions' => (object) ['transaction' => $str_txn_ref], 'keys' => [(object) ['path' => [(object) ['kind' => 'Test', 'id' => $str_id]], 'partitionId' => (object) ['projectId' => self::TEST_PROJECT]]]]], ['found' => [(object) ['entity' => (object) ['key' => (object) ['path' => [(object) ['kind' => 'Test', 'id' => $str_id]]], 'properties' => (object) ['name' => (object) ['excludeFromIndexes' => false, 'stringValue' => 'Tom']]], 'version' => '123', 'cursor' => 'gfuh37f86gyu23']]]);
     $obj_gateway->setHttpClient($obj_http);
     $obj_entity = $obj_store->fetchById($str_id);
     $this->assertInstanceOf('\\GDS\\Entity', $obj_entity);
     $this->assertEquals($str_id, $obj_entity->getKeyId());
     $this->assertEquals('Tom', $obj_entity->name);
     $this->validateHttpClient($obj_http);
 }