Skip to content

Commit

Permalink
fixing tests WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Oct 30, 2024
1 parent d9b959c commit 8702a30
Show file tree
Hide file tree
Showing 10 changed files with 403 additions and 500 deletions.
3 changes: 2 additions & 1 deletion Spanner/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"phpdocumentor/reflection-docblock": "^5.3",
"erusev/parsedown": "^1.6",
"google/cloud-pubsub": "^2.0",
"dg/bypass-finals": "^1.7"
"dg/bypass-finals": "^1.7",
"dms/phpunit-arraysubset-asserts": "^0.5.0"
},
"suggest": {
"ext-protobuf": "Provides a significant increase in throughput over the pure PHP protobuf implementation. See https://cloud.google.com/php/grpc for installation instructions.",
Expand Down
2 changes: 1 addition & 1 deletion Spanner/src/Instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function __construct(
private InstanceAdminClient $instanceAdminClient,
private DatabaseAdminClient $databaseAdminClient,
private Serializer $serializer,
private stirng $projectId,
private string $projectId,
private string $name,
private bool $returnInt64AsObject = false,
private array $info = [],
Expand Down
4 changes: 3 additions & 1 deletion Spanner/src/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Google\ApiCore\ArrayTrait;
use Google\Cloud\Core\TimeTrait;
use Google\Cloud\Core\ValidateTrait;
use Google\Cloud\Core\RequestProcessorTrait;
use Google\Cloud\Spanner\Batch\QueryPartition;
use Google\Cloud\Spanner\Batch\ReadPartition;
use Google\Cloud\Spanner\Session\Session;
Expand Down Expand Up @@ -55,6 +56,7 @@ class Operation
use ApiHelperTrait;
use ArrayTrait;
use RequestTrait;
use RequestProcessorTrait;
use MutationTrait;
use TimeTrait;
use ValidateTrait;
Expand Down Expand Up @@ -659,7 +661,7 @@ public function createSession($databaseName, array $options = [])
]];

$request = $this->serializer->decodeMessage(new CreateSessionRequest(), $data);
$callOptions = $this->addResourcePrefixHeader($callOptions, $this->getDatabaseNameFromSession($session));
$callOptions = $this->addResourcePrefixHeader($callOptions, $databaseName);
$callOptions = $this->addLarHeader($callOptions, $this->routeToLeader);

$response = $this->spannerClient->createSession($request, $callOptions);
Expand Down
6 changes: 4 additions & 2 deletions Spanner/src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ public function __construct(
private Session $session,
private ?string $transactionId = null,
private bool $isRetry = false,
private ?string $tag = null,
private array $options = [],
?string $tag = null,
array $options = [],
private ?ValueMapper $mapper = null
) {
$this->type = ($transactionId || isset($options['begin']))
Expand All @@ -116,6 +116,8 @@ public function __construct(
}

$this->context = SessionPoolInterface::CONTEXT_READWRITE;
$this->options = $options;
$this->tag =$tag;
}

/**
Expand Down
115 changes: 0 additions & 115 deletions Spanner/tests/RequestHandlingTestTrait.php

This file was deleted.

6 changes: 3 additions & 3 deletions Spanner/tests/Snippet/DatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public function testRunTransaction()
])
);

$this->mockSendRequest(SpannerClient::class, 'rollback', null, null, 0);
$this->spannerClient->rollback(Argument::cetera())->shouldNotBeCalled();

$this->refreshOperation($this->database, $this->requestHandler->reveal(), $this->serializer);

Expand All @@ -499,9 +499,9 @@ public function testRunTransaction()

public function testRunTransactionRollback()
{
$this->mockSendRequest(SpannerClient::class, 'beginTransaction', null, null, 0);
$this->spannerClient->beginTransaction(Argument::cetera())->shouldNotBeCalled();

$this->mockSendRequest(SpannerClient::class, 'commit', null, null, 0);
$this->spannerClient->commit(Argument::cetera())->shouldNotBeCalled();

$this->mockSendRequest(SpannerClient::class, 'rollback', null, null, 1);

Expand Down
20 changes: 10 additions & 10 deletions Spanner/tests/Unit/DatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -832,9 +832,9 @@ public function testSnapshotNestedTransaction()
// Begin transaction RPC is skipped when begin is inlined
// and invoked only if `begin` fails or if commit is the
// sole operation in the transaction.
$this->mockSendRequest(SpannerClient::class, 'beginTransaction', null, null, 0);
$this->spannerClient->beginTransaction(Argument::cetera())->shouldNotBeCalled();

$this->mockSendRequest(SpannerClient::class, 'rollback', null, null, 0);
$this->spannerClient->rollback(Argument::cetera())->shouldNotBeCalled();

$this->refreshOperation($this->database, $this->requestHandler->reveal(), $this->serializer);

Expand Down Expand Up @@ -900,9 +900,9 @@ public function testRunTransactionNoCommit()
{
$this->expectException(\InvalidArgumentException::class);

$this->mockSendRequest(SpannerClient::class, 'beginTransaction', null, null, 0);
$this->spannerClient->beginTransaction(Argument::cetera())->shouldNotBeCalled();

$this->mockSendRequest(SpannerClient::class, 'rollback', null, null, 0);
$this->spannerClient->rollback(Argument::cetera())->shouldNotBeCalled();

$this->refreshOperation($this->database, $this->requestHandler->reveal(), $this->serializer);

Expand All @@ -913,9 +913,9 @@ public function testRunTransactionNestedTransaction()
{
$this->expectException(\BadMethodCallException::class);

$this->mockSendRequest(SpannerClient::class, 'beginTransaction', null, null, 0);
$this->spannerClient->beginTransaction(Argument::cetera())->shouldNotBeCalled();

$this->mockSendRequest(SpannerClient::class, 'rollback', null, null, 0);
$this->spannerClient->rollback(Argument::cetera())->shouldNotBeCalled();

$this->refreshOperation($this->database, $this->requestHandler->reveal(), $this->serializer);

Expand Down Expand Up @@ -1074,9 +1074,9 @@ public function testTransactionNestedTransaction()
{
$this->expectException(\BadMethodCallException::class);

$this->mockSendRequest(SpannerClient::class, 'beginTransaction', null, null, 0);
$this->spannerClient->beginTransaction(Argument::cetera())->shouldNotBeCalled();

$this->mockSendRequest(SpannerClient::class, 'rollback', null, null, 0);
$this->spannerClient->rollback(Argument::cetera())->shouldNotBeCalled();

$this->refreshOperation($this->database, $this->requestHandler->reveal(), $this->serializer);

Expand Down Expand Up @@ -2099,7 +2099,7 @@ function ($args) use ($sql) {
$error,
Database::MAX_RETRIES
);
$this->mockSendRequest(SpannerClient::class, 'commit', null, null, 0);
$this->spannerClient->commit(Argument::cetera())->shouldNotBeCalled();
$this->refreshOperation($this->database, $this->requestHandler->reveal(), $this->serializer);

$this->database->runTransaction(function ($t) use ($sql) {
Expand Down Expand Up @@ -2336,7 +2336,7 @@ private function resultGeneratorWithError()
private function stubCommit($withTransaction = true)
{
if ($withTransaction) {
$this->mockSendRequest(SpannerClient::class, 'beginTransaction', null, null, 0);
$this->spannerClient->beginTransaction(Argument::cetera())->shouldNotBeCalled();
} else {
$this->mockSendRequest(
SpannerClient::class,
Expand Down
1 change: 1 addition & 0 deletions Spanner/tests/Unit/InstanceConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Google\ApiCore\ApiException;
use Google\Cloud\Core\Testing\GrpcTestTrait;
use Google\Cloud\Core\Testing\TestHelpers;
use Google\Cloud\Core\Serializer;
use Google\Cloud\Spanner\Admin\Instance\V1\Client\InstanceAdminClient;
use Google\Cloud\Spanner\Admin\Instance\V1\InstanceConfig;
use Google\Cloud\Spanner\Admin\Instance\V1\DeleteInstanceConfigRequest;
Expand Down
2 changes: 1 addition & 1 deletion Spanner/tests/Unit/OperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ function ($args) {

public function testSnapshotSingleUse()
{
$this->mockSendRequest(SpannerClient::class, 'beginTransaction', null, null, 0);
$this->spannerClient->beginTransaction(Argument::cetera())->shouldNotBeCalled();

$this->operation->___setProperty('requestHandler', $this->requestHandler->reveal());
$this->operation->___setProperty('serializer', $this->serializer);
Expand Down
Loading

0 comments on commit 8702a30

Please sign in to comment.