Skip to content

Commit

Permalink
feat: inject database info on list databases (#2656)
Browse files Browse the repository at this point in the history
* refactor: inject database info on list databases

* refactor: default info as []
  • Loading branch information
AVaksman committed Feb 4, 2020
1 parent b16dd8b commit e6308a6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Spanner/src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,16 @@ public function __construct(
$projectId,
$name,
SessionPoolInterface $sessionPool = null,
$returnInt64AsObject = false
$returnInt64AsObject = false,
array $info = []
) {
$this->connection = $connection;
$this->instance = $instance;
$this->projectId = $projectId;
$this->name = $this->fullyQualifiedDatabaseName($name);
$this->sessionPool = $sessionPool;
$this->operation = new Operation($connection, $returnInt64AsObject);
$this->info = $info;

if ($this->sessionPool) {
$this->sessionPool->setDatabase($this);
Expand Down
5 changes: 3 additions & 2 deletions Spanner/src/Instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ public function database($name, array $options = [])
$this->projectId,
$name,
isset($options['sessionPool']) ? $options['sessionPool'] : null,
$this->returnInt64AsObject
$this->returnInt64AsObject,
isset($options['database']) ? $options['database'] : []
);
}

Expand Down Expand Up @@ -476,7 +477,7 @@ public function databases(array $options = [])
return new ItemIterator(
new PageIterator(
function (array $database) {
return $this->database($database['name']);
return $this->database($database['name'], ['database' => $database]);
},
[$this->connection, 'listDatabases'],
$options + ['instance' => $this->name],
Expand Down
5 changes: 5 additions & 0 deletions Spanner/tests/Unit/InstanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ public function testDatabases()
$this->connection->listDatabases(Argument::any())
->shouldBeCalled()
->willReturn(['databases' => $databases]);
$this->connection->getDatabase()->shouldNotBeCalled();

$this->instance->___setProperty('connection', $this->connection->reveal());

Expand All @@ -320,6 +321,10 @@ public function testDatabases()
$this->assertCount(2, $dbs);
$this->assertEquals('database1', DatabaseAdminClient::parseName($dbs[0]->name())['database']);
$this->assertEquals('database2', DatabaseAdminClient::parseName($dbs[1]->name())['database']);

// Make sure the database->info is prefilled.
$this->assertEquals($databases[0], $dbs[0]->info());
$this->assertEquals($databases[1], $dbs[1]->info());
}

public function testDatabasesPaged()
Expand Down

0 comments on commit e6308a6

Please sign in to comment.