Skip to content

Commit 69c9dcf

Browse files
committed
ensure instance state is always int
1 parent 3d49c5e commit 69c9dcf

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

Spanner/src/Instance.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,13 @@ public function create(InstanceConfiguration $config, array $options = []): Long
332332
* ```
333333
*
334334
* @param array $options [optional] Configuration options.
335-
* @return int|null
335+
* @return int
336336
*/
337-
public function state(array $options = []): int|null
337+
public function state(array $options = []): int
338338
{
339339
$info = $this->info($options);
340340

341-
// @TODO investigate why state is now 0 but in v1 it was unset
342-
return (isset($info['state']) && $info['state'] !== 0)
343-
? $info['state']
344-
: null;
341+
return $info['state'] ?? State::STATE_UNSPECIFIED;
345342
}
346343

347344
/**

Spanner/tests/Unit/InstanceTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Google\Cloud\Core\Testing\GrpcTestTrait;
2727
use Google\Cloud\Core\LongRunning\LongRunningOperation;
2828
use Google\Cloud\Spanner\Admin\Database\V1\Backup as BackupProto;
29+
use Google\Cloud\Spanner\Admin\Database\V1\Backup\State;
2930
use Google\Cloud\Spanner\Admin\Database\V1\Client\DatabaseAdminClient;
3031
use Google\Cloud\Spanner\Admin\Database\V1\Database as DatabaseProto;
3132
use Google\Cloud\Spanner\Admin\Database\V1\ListBackupOperationsResponse;
@@ -264,7 +265,7 @@ public function testState()
264265
$this->assertEquals(Instance::STATE_READY, $this->instance->state());
265266
}
266267

267-
public function testStateIsNull()
268+
public function testStateIsUnspecified()
268269
{
269270
$this->instanceAdminClient->getInstance(
270271
Argument::that(function ($request) {
@@ -277,7 +278,7 @@ public function testStateIsNull()
277278
->shouldBeCalledOnce()
278279
->willReturn(new InstanceProto());
279280

280-
$this->assertNull($this->instance->state());
281+
$this->assertEquals(State::STATE_UNSPECIFIED, $this->instance->state());
281282
}
282283

283284
public function testUpdate()

0 commit comments

Comments
 (0)