diff --git a/phpunit.xml b/phpunit.xml index ccdaa969e..783265d80 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,7 +7,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false"> + stopOnFailure="true"> ./tests/unit diff --git a/src/Database/Adapter.php b/src/Database/Adapter.php index 527f350e6..96dd8a273 100644 --- a/src/Database/Adapter.php +++ b/src/Database/Adapter.php @@ -273,13 +273,22 @@ protected function trigger(string $event, mixed $query): mixed abstract public function ping(): bool; /** - * Execute raw command - * @param string $command + * Execute raw command with no response + * @param mixed $query * * @return mixed * @throws \Throwable */ - abstract public function execute(string $command): mixed; + abstract public function executeWrite(mixed $query): bool; + + /** + * Execute raw command that returns a response + * @param mixed $query + * + * @return mixed + * @throws \Throwable + */ + abstract public function executeRead(mixed $query): mixed; /** * Create Database diff --git a/src/Database/Adapter/DataAPIMariaDB.php b/src/Database/Adapter/DataAPIMariaDB.php index 5872262d7..53c10600c 100644 --- a/src/Database/Adapter/DataAPIMariaDB.php +++ b/src/Database/Adapter/DataAPIMariaDB.php @@ -26,13 +26,26 @@ public function __construct(string $endpoint, string $secret, string $database) } /** - * Execute raw command + * Execute raw command with no response * @param mixed $query * * @return mixed * @throws \Throwable */ - public function execute(mixed $query): mixed + public function executeWrite(mixed $query): bool + { + $this->query($this->endpoint, $this->secret, $this->database, $query); + return true; + } + + /** + * Execute raw command that returns a response + * @param mixed $query + * + * @return mixed + * @throws \Throwable + */ + public function executeRead(mixed $query): mixed { return $this->query($this->endpoint, $this->secret, $this->database, $query); } diff --git a/src/Database/Adapter/Mongo.php b/src/Database/Adapter/Mongo.php index 13bb38ca3..7693e8e3b 100644 --- a/src/Database/Adapter/Mongo.php +++ b/src/Database/Adapter/Mongo.php @@ -70,15 +70,27 @@ public function ping(): bool return $this->getClient()->query(['ping' => 1])->ok ?? false; } + /** + * Execute raw command with no response + * @param mixed $query + * + * @return mixed + * @throws \Throwable + */ + public function executeWrite(mixed $query): bool + { + // Not needed until we need Mongo Data API adapter + throw new Exception('Not implemented'); + } + /** - * Execute raw command + * Execute raw command that returns a response * @param mixed $query * * @return mixed - * @throws Exception - * @throws MongoException + * @throws \Throwable */ - public function execute(mixed $query): mixed + public function executeRead(mixed $query): mixed { // Not needed until we need Mongo Data API adapter throw new Exception('Not implemented'); diff --git a/src/Database/Adapter/SQL.php b/src/Database/Adapter/SQL.php index 32c658612..00189f979 100644 --- a/src/Database/Adapter/SQL.php +++ b/src/Database/Adapter/SQL.php @@ -36,28 +36,46 @@ public function __construct(mixed $pdo) */ public function ping(): bool { - $query = $this->getPDO() - ->prepare("SELECT 1;") - ->queryString; + $stmt = $this->getPDO()->prepare("SELECT 1;"); + $query = $stmt->queryString; - return $this->execute($query); + return $this->executeWrite($query); } /** - * Execute raw command + * Execute raw command with no response * @param mixed $query * * @return mixed - * @throws Exception - * @throws PDOException + * @throws \Throwable */ - public function execute(mixed $query): mixed + public function executeWrite(mixed $query): bool { return $this->getPDO() ->prepare($query) ->execute(); } + /** + * Execute raw command that returns a response + * @param mixed $query + * + * @return mixed + * @throws \Throwable + */ + public function executeRead(mixed $query): mixed + { + $stmt = $this->getPDO()->prepare($query); + $response = $stmt->fetchAll(); + + \var_dump($query); + \var_dump($response); + + $stmt->closeCursor(); + + return $response; + } + /** * Check if Database exists * Optionally check if collection exists in Database @@ -92,8 +110,7 @@ public function exists(string $database, ?string $collection = null): bool $stmt->execute(); - $document = $stmt->fetchAll(); - $stmt->closeCursor(); + $document = $this->executeRead($stmt->queryString); if (empty($document)) { return false;