Skip to content

Commit

Permalink
more test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Nov 11, 2024
1 parent aa226ec commit cb49912
Show file tree
Hide file tree
Showing 12 changed files with 406 additions and 418 deletions.
13 changes: 12 additions & 1 deletion Spanner/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"require": {
"php": "^8.0",
"ext-grpc": "*",
"google/cloud-core": "^1.60.0",
"google/cloud-core": "1.60",
"google/gax": "dev-result-function as 1.40.0"
},
"require-dev": {
Expand Down Expand Up @@ -42,5 +42,16 @@
"psr-4": {
"Google\\Cloud\\Spanner\\Tests\\": "tests"
}
},
"repositories": {
"google-cloud": {
"type": "path",
"url": "../Core",
"options": {
"versions": {
"google/cloud-core": "1.60"
}
}
}
}
}
2 changes: 1 addition & 1 deletion Spanner/src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -2352,7 +2352,7 @@ function ($callOptions) use ($data) {
}

$request = $this->serializer->decodeMessage(new ListDatabaseOperationsRequest(), $data);
$callOptions = $this->addResourcePrefixHeader($callOptions, $this->instance->name);
$callOptions = $this->addResourcePrefixHeader($callOptions, $this->instance->name());

$response = $this->databaseAdminClient->listDatabaseOperations($request, $callOptions);
return $this->handleResponse($response);
Expand Down
3 changes: 2 additions & 1 deletion Spanner/src/Instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ public function state(array $options = [])
{
$info = $this->info($options);

return (isset($info['state']))
// @TODO investigate why state is now 0 but in v1 it was unset
return (isset($info['state']) && $info['state'] !== 0)
? $info['state']
: null;
}
Expand Down
2 changes: 1 addition & 1 deletion Spanner/src/InstanceConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
class InstanceConfiguration
{
use ApiHelperTrait;
// use RequestTrait;
use RequestTrait;
use RequestProcessorTrait;

/**
Expand Down
17 changes: 17 additions & 0 deletions Spanner/src/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,23 @@ private function formatPartitionQueryOptions(array $args)
return $args;
}

/**
* Conditionally unset the LAR header.
*
* @param array $args Request arguments.
* @param bool $value Whether to set or unset the LAR header.
* @return array
*/
private function conditionallyUnsetLarHeader(
array $args,
bool $value = true
) {
if (!$value) {
unset($args['headers'][$this->larHeader]);
}
return $args;
}

/**
* Represent the class in a more readable and digestable fashion.
*
Expand Down
17 changes: 0 additions & 17 deletions Spanner/src/RequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,6 @@ private function addLarHeader(
return $args;
}

/**
* Conditionally unset the LAR header.
*
* @param array $args Request arguments.
* @param bool $value Whether to set or unset the LAR header.
* @return array
*/
private function conditionallyUnsetLarHeader(
array $args,
bool $value = true
) {
if (!$value) {
unset($args['headers'][$this->larHeader]);
}
return $args;
}

/**
* Add the `google-cloud-resource-prefix` header value to the request.
*
Expand Down
3 changes: 2 additions & 1 deletion Spanner/tests/Unit/BackupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public function setUp(): void
$this->instance->database(Argument::any())->willReturn($this->database);

$this->operationResponse = $this->prophesize(OperationResponse::class);
$this->operationResponse->withResultFunction(Argument::any())->willReturn($this->operationResponse->reveal());
$this->operationResponse->withResultFunction(Argument::type('callable'))
->willReturn($this->operationResponse->reveal());

$this->expireTime = new DateTime("+7 hours");
$this->versionTime = new DateTime("-2 hours");
Expand Down
10 changes: 6 additions & 4 deletions Spanner/tests/Unit/DatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ public function setUp(): void
);

$this->operationResponse = $this->prophesize(OperationResponse::class);
$this->operationResponse->withResultFunction(Argument::any())->willReturn($this->operationResponse->reveal());
$this->operationResponse->withResultFunction(Argument::type('callable'))
->willReturn($this->operationResponse->reveal());

}

Expand Down Expand Up @@ -279,9 +280,10 @@ public function testCreateBackup()

public function testBackups()
{
$backup1 = DatabaseAdminClient::backupName(self::PROJECT, self::INSTANCE, 'backup1');
$backup2 = DatabaseAdminClient::backupName(self::PROJECT, self::INSTANCE, 'backup2');
$backups = [new Backup(['name' => $backup1]), new Backup(['name' => $backup2])];
$backups = [
new Backup(['name' => DatabaseAdminClient::backupName(self::PROJECT, self::INSTANCE, 'backup1')]),
new Backup(['name' => DatabaseAdminClient::backupName(self::PROJECT, self::INSTANCE, 'backup2')])
];

$page = $this->prophesize(Page::class);
$page->getResponseObject()
Expand Down
5 changes: 0 additions & 5 deletions Spanner/tests/Unit/Fixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ public static function STREAMING_READ_ACCEPTANCE_FIXTURE()
return __DIR__ . '/fixtures/streaming-read-acceptance-test.json';
}

public static function INSTANCE_FIXTURE()
{
return __DIR__ . '/fixtures/instance.json';
}

public static function INSTANCE_CONFIG_FIXTURE()
{
return __DIR__ . '/fixtures/instanceConfig.json';
Expand Down
4 changes: 2 additions & 2 deletions Spanner/tests/Unit/InstanceConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

use Google\ApiCore\OperationResponse;
use Google\ApiCore\ApiException;
use Google\ApiCore\Serializer;
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 Expand Up @@ -240,7 +240,7 @@ public function testUpdateWithChanges()
Argument::type('array')
)
->shouldBeCalledOnce()
->willReturn($this->getOperationResponseMock());
->willReturn($this->prophesize(OperationResponse::class)->reveal());

$instanceConfig = new InstanceConfiguration(
$this->instanceAdminClient->reveal(),
Expand Down
Loading

0 comments on commit cb49912

Please sign in to comment.