diff --git a/src/Driver/Test/TestDriver.php b/src/Driver/Test/TestDriver.php index b13aad3..77c5c83 100644 --- a/src/Driver/Test/TestDriver.php +++ b/src/Driver/Test/TestDriver.php @@ -47,12 +47,11 @@ public function addTable(string $name, array $entries): static /** * @param string $name * @return TestTable - * @throws Exception */ public function getTable(string $name): TestTable { if (!$this->tables[$name]) { - throw new Exception("Table " . $name . " does not exist."); + $this->tables[$name] = new TestTable($name); } return $this->tables[$name]; } @@ -64,10 +63,8 @@ public function getTable(string $name): TestTable */ public function addEntry(string $tableName, array $entry): static { - if (!isset($this->tables[$tableName])) { - $this->tables[$tableName] = new TestTable($tableName); - } - $this->tables[$tableName]->addEntry(new TestTableEntry($entry)); + $table = $this->getTable($tableName); + $table->addEntry(new TestTableEntry($entry)); return $this; } diff --git a/test/tests/TestDriverTest.php b/test/tests/TestDriverTest.php index c4e32a3..c0c58a6 100644 --- a/test/tests/TestDriverTest.php +++ b/test/tests/TestDriverTest.php @@ -2,6 +2,8 @@ namespace Aternos\Model\Test\Tests; +use Aternos\Model\Driver\DriverRegistry; +use Aternos\Model\Driver\Test\TestDriver; use Aternos\Model\Query\CountField; use Aternos\Model\Query\DeleteQuery; use Aternos\Model\Query\OrderField; @@ -12,6 +14,7 @@ use Aternos\Model\Test\Src\TestModel; use Exception; use PHPUnit\Framework\TestCase; +use PHPUnit\Util\Test; class TestDriverTest extends TestCase { @@ -42,6 +45,16 @@ public function testGet(): void $this->assertEquals(1, $model->number); } + public function testGetOnNonExistingTable(): void + { + /** @var TestDriver $driver */ + $driver = DriverRegistry::getInstance()->getDriver("test"); + $driver->clearTables(); + + $model = TestModel::get("1B"); + $this->assertNull($model); + } + /** * @return void * @throws Exception