Skip to content

Commit

Permalink
Added tests for begin transactions inc cross-group
Browse files Browse the repository at this point in the history
  • Loading branch information
twalder-docnet committed Jun 12, 2015
1 parent 0a999e3 commit edac4b8
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/ProtoBufTransactionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Copyright 2015 Tom Walder
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Tests for Protocol Buffer Transactions
*
* @author Tom Walder <tom@docnet.nu>
*/
class ProtoBufTransactionTest extends GDSTest {

/**
* 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();
}

/**
* Start cross-group transaction
*/
public function testBeginCrossGroupTransaction()
{
$obj_request = new \google\appengine\datastore\v4\BeginTransactionRequest();
$obj_request->setCrossGroup(TRUE);
$this->apiProxyMock->expectCall('datastore_v4', 'BeginTransaction', $obj_request, new \google\appengine\datastore\v4\BeginTransactionResponse());
$this->createBasicStore()->beginTransaction(TRUE);
$this->apiProxyMock->verify();
}

}

0 comments on commit edac4b8

Please sign in to comment.