From a8ad3126c8f84ad42d0d5583e3378689bfd03c7e Mon Sep 17 00:00:00 2001 From: Kirill Yegorov Date: Tue, 5 Jan 2021 22:26:21 +0300 Subject: [PATCH 1/2] phpunit migrate configuration --- phpunit.xml.dist | 51 ++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0de7a728a..203671031 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,31 +1,22 @@ - - - - ./tests/unit/ - - - - ./application/classes - ./src - - ./ - ./bootstrap.php - ./console.php - ./console_client.php - - - - - - + + + + + ./application/classes + ./src + + + ./ + ./bootstrap.php + ./console.php + ./console_client.php + + + + + + + ./tests/unit/ + + From 17a6c9e0aec4d91bc84ae86811b5c49d270f0fd8 Mon Sep 17 00:00:00 2001 From: Kirill Yegorov Date: Fri, 12 Feb 2021 00:47:22 +0300 Subject: [PATCH 2/2] Models and query should throws exception for fetch methods like fetchAll, fetchCol, fetchOne. Fetch methods return an empty array on connection error. It can cause buisnes logic errors. --- application/configs/common/dist/versions.php | 2 +- composer.json | 2 +- src/Dvelum/Db/Model.php | 2 ++ src/Dvelum/Db/Query.php | 13 +++++++++---- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/application/configs/common/dist/versions.php b/application/configs/common/dist/versions.php index 42fac9580..7c8a940cb 100644 --- a/application/configs/common/dist/versions.php +++ b/application/configs/common/dist/versions.php @@ -1,4 +1,4 @@ '3.1.0', + 'core'=>'3.2.0', ); \ No newline at end of file diff --git a/composer.json b/composer.json index dc5ee0fa3..7329a7cfe 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "dvelum/dvelum-core", - "version": "3.1.0", + "version": "3.2.0", "type": "project", "description": "DVelum 3.x core", "keywords": ["dvelum","php"], diff --git a/src/Dvelum/Db/Model.php b/src/Dvelum/Db/Model.php index 002e2ebee..399aeae11 100644 --- a/src/Dvelum/Db/Model.php +++ b/src/Dvelum/Db/Model.php @@ -194,6 +194,7 @@ public function update(int $recordId, array $data, string $keyField = 'id'): boo * @param int $recordId * @param string $keyField * @return array + * @throws \Exception */ public function getItem(int $recordId, string $keyField = 'id'): array { @@ -222,6 +223,7 @@ public function getLogsAdapter(): ?LogInterface * @param int $lifetime * @param string $keyField * @return array + * @throws \Exception */ public function getCachedItem(int $recordId, int $lifetime, string $keyField = 'id'): array { diff --git a/src/Dvelum/Db/Query.php b/src/Dvelum/Db/Query.php index 8ac735e42..8773e3702 100644 --- a/src/Dvelum/Db/Query.php +++ b/src/Dvelum/Db/Query.php @@ -293,6 +293,7 @@ public function __toString(): string /** * Fetch all records * @return array + * @throws \Exception */ public function fetchAll(): array { @@ -300,13 +301,14 @@ public function fetchAll(): array return $this->db->fetchAll($this->__toString()); } catch (\Exception $e) { $this->model->logError($e->getMessage()); - return []; + throw $e; } } /** * Fetch one * @return mixed + * @throws \Exception */ public function fetchOne() { @@ -314,13 +316,14 @@ public function fetchOne() return $this->db->fetchOne($this->__toString()); } catch (\Exception $e) { $this->model->logError($e->getMessage()); - return null; + throw $e; } } /** * Fetch first result row * @return array + * @throws \Exception */ public function fetchRow(): array { @@ -332,13 +335,14 @@ public function fetchRow(): array return $result; } catch (\Exception $e) { $this->model->logError($e->getMessage()); - return []; + throw $e; } } /** * Fetch column * @return array + * @throws \Exception */ public function fetchCol(): array { @@ -346,13 +350,14 @@ public function fetchCol(): array return $this->db->fetchCol($this->__toString()); } catch (\Exception $e) { $this->model->logError($e->getMessage()); - return []; + throw $e; } } /** * Count the number of rows that satisfy the filters * @return int + * @throws \Exception */ public function getCount(): int {