Skip to content

Commit

Permalink
Merge pull request #90 from xsist10/backward_reference_fix
Browse files Browse the repository at this point in the history
Fixed a backwards reference to databases.
  • Loading branch information
xsist10 authored Jan 3, 2023
2 parents 29a41f8 + 9b14b06 commit e514120
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Engine/Entity/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public function getAccount(string $username, string $host): ?Account
*/
public function setAccounts(Account...$accounts): void
{
foreach ($accounts as $account) {
$account->setDatabase($this);
}
$this->accounts = $accounts;
}

Expand All @@ -125,6 +128,7 @@ public function setAccounts(Account...$accounts): void
*/
public function addAccount(Account $account): void
{
$account->setDatabase($this);
$this->accounts[] = $account;
}

Expand Down
8 changes: 6 additions & 2 deletions tests/Engine/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ protected function createVirtualTable(array $override = []): Table
);
}

protected function createAccount(string $user, string $host): Account
protected function createAccount(string $user, string $host, Database $database = null): Account
{
return Account::withRaw($user, $host);
$account = Account::withRaw($user, $host);
if ($database) {
$account->setDatabase($database);
}
return $account;
}
}
4 changes: 2 additions & 2 deletions tests/Engine/Entity/DatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function test__toString()
public function test__getAccount()
{
$this->assertEquals(
$this->createAccount('bob', 'localhost'),
$this->createAccount('bob', 'localhost', $this->database),
$this->database->getAccount('bob', 'localhost'),
"Verify that we get the expected Account."
);
Expand All @@ -59,7 +59,7 @@ public function test__getAccount()
"Our fuzzy domain should not match for Bob."
);
$this->assertEquals(
$this->createAccount('alice', '%'),
$this->createAccount('alice', '%', $this->database),
$this->database->getAccount('alice', 'localhost'),
"Our fuzzy domain should match for Alice."
);
Expand Down

0 comments on commit e514120

Please sign in to comment.