Skip to content

Commit

Permalink
Merge pull request #7 from aternosorg/test-driver
Browse files Browse the repository at this point in the history
allow get on non existing table
  • Loading branch information
matthi4s authored Jun 30, 2023
2 parents 5b61f0b + 9cc2fa1 commit 191697a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/Driver/Test/TestDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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;
}

Expand Down
13 changes: 13 additions & 0 deletions test/tests/TestDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,6 +14,7 @@
use Aternos\Model\Test\Src\TestModel;
use Exception;
use PHPUnit\Framework\TestCase;
use PHPUnit\Util\Test;

class TestDriverTest extends TestCase
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 191697a

Please sign in to comment.