diff --git a/src/Query/Query.php b/src/Query/Query.php index b4f933d..1e23373 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -24,7 +24,7 @@ class Query implements QueryInterface /** * @var string */ - protected string $table; + protected string $table = ""; /** * @var array @@ -185,7 +185,7 @@ public function getQuery(): string $having = $this->connection->getSqlCondition($this->having); if (!$this->table) { - throw new DatabaseException("Undefined from fro query"); + throw new DatabaseException("Table Not Found From Query"); } return $driver->createSelectQuery( diff --git a/tests/Src/QueryTest.php b/tests/Src/QueryTest.php index ca44aec..4ac5740 100644 --- a/tests/Src/QueryTest.php +++ b/tests/Src/QueryTest.php @@ -3,6 +3,7 @@ namespace Jtrw\DAO\Tests\Src; use Jtrw\DAO\DataAccessObjectInterface; +use Jtrw\DAO\Exceptions\DatabaseException; use Jtrw\DAO\Query\Query; use Jtrw\DAO\Tests\DbConnector; use PHPUnit\Framework\TestCase; @@ -14,12 +15,18 @@ class QueryTest extends TestCase private DataAccessObjectInterface $db; + /** + * @return void + */ public function setUp(): void { $this->db = DbConnector::getInstance(); parent::setUp(); // TODO: Change the autogenerated stub } + /** + * @return void + */ public function testFetch() { $query = new Query($this->db); @@ -39,6 +46,9 @@ public function testFetch() Assert::assertEquals($result['caption'], $values['caption']); } + /** + * @return void + */ public function testFetchAll() { $query = new Query($this->db); @@ -61,6 +71,9 @@ public function testFetchAll() Assert::assertEquals($result[1]['id'], $values[0]['id']); } + /** + * @return void + */ public function testLimitFetchAlll() { $query = new Query($this->db); @@ -84,6 +97,9 @@ public function testLimitFetchAlll() Assert::assertEquals($result[0]['caption'], $values['caption']); } + /** + * @return void + */ public function testJoin() { $query = new Query($this->db); @@ -113,6 +129,9 @@ public function testJoin() Assert::assertEquals($result[0]['caption'], $values['caption']); } + /** + * @return void + */ public function testJoins() { $query = new Query($this->db); @@ -142,6 +161,28 @@ public function testJoins() Assert::assertEquals($result[0]['caption'], $values['caption']); } + /** + * @return void + */ + public function testTableNotFound() + { + $query = new Query($this->db); + try { + $query->select("caption")->fetch(); + $this->fail('DatabaseException was not thrown'); + } catch (DatabaseException $exp) { + $this->assertSame( + [ + 'Table Not Found From Query', + ], + [$exp->getMessage()] + ); + } + } + + /** + * @return array|array[] + */ private function createItems(): array { $values = [ @@ -163,6 +204,10 @@ private function createItems(): array return $values; } + /** + * @param array $values + * @return int + */ private function createItem(array $values): int { $idSetting = $this->db->insert(static::TABLE_SETTINGS, $values);