Skip to content

Commit

Permalink
test null default connection within ConnectionLocator and throw Conne…
Browse files Browse the repository at this point in the history
…ctionNotFound from getDefault() on a null default
  • Loading branch information
srjlewis committed Nov 4, 2021
1 parent 04b6657 commit 42146a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ConnectionLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,14 @@ public function setDefault(callable $callable): void
*
* @return ExtendedPdoInterface
*
* @throws Exception\ConnectionNotFound
*/
public function getDefault(): ExtendedPdoInterface
{
if (! $this->default) {
throw new Exception\ConnectionNotFound("default");
}

if (! $this->default instanceof ExtendedPdo) {
$this->default = call_user_func($this->default);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/ConnectionLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ protected function newLocator($read = [], $write = [])
return new ConnectionLocator($this->default, $read, $write);
}

public function testNullDefault()
{
$locator = new ConnectionLocator(null, $this->read, $this->write);
$this->expectException('Aura\Sql\Exception\ConnectionNotFound');
$locator->getDefault();
}

public function testGetDefault()
{
$locator = $this->newLocator();
Expand Down

0 comments on commit 42146a0

Please sign in to comment.