From bb18c2073f59e846beff0a1396fb1d1560a24ae8 Mon Sep 17 00:00:00 2001 From: Adam Kadlec Date: Sun, 4 Aug 2024 23:17:09 +0200 Subject: [PATCH 1/2] Override exceptions --- src/Crud/Create/EntityCreator.php | 8 +++++--- src/Crud/Delete/EntityDeleter.php | 19 +++++++++++-------- src/Crud/Update/EntityUpdater.php | 9 ++++++--- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/Crud/Create/EntityCreator.php b/src/Crud/Create/EntityCreator.php index 8f2f38b..0422eca 100644 --- a/src/Crud/Create/EntityCreator.php +++ b/src/Crud/Create/EntityCreator.php @@ -63,11 +63,9 @@ public function __construct( } /** - * @throws DBAL\Exception\UniqueConstraintViolationException * @throws Exceptions\EntityCreation * @throws Exceptions\InvalidArgument * @throws Exceptions\InvalidState - * @throws ORM\Exception\ORMException */ public function create(Utils\ArrayHash $values, Entities\IEntity|null $entity = null): Entities\IEntity { @@ -121,7 +119,11 @@ public function create(Utils\ArrayHash $values, Entities\IEntity|null $entity = Utils\Arrays::invoke($this->afterAction, $entity, $values); if ($this->getFlush()) { - $this->entityManager->flush(); + try { + $this->entityManager->flush(); + } catch (DBAL\Exception\UniqueConstraintViolationException | ORM\Exception\ORMException $ex) { + throw new Exceptions\InvalidState('Entity could not be created', $ex->getCode(), $ex); + } } return $entity; diff --git a/src/Crud/Delete/EntityDeleter.php b/src/Crud/Delete/EntityDeleter.php index 482e25f..0298302 100644 --- a/src/Crud/Delete/EntityDeleter.php +++ b/src/Crud/Delete/EntityDeleter.php @@ -43,9 +43,8 @@ class EntityDeleter extends Crud\CrudManager public array $afterAction = []; /** - * @throws DBAL\Exception * @throws Exceptions\InvalidArgument - * @throws ORM\Exception\ORMException + * @throws Exceptions\InvalidState */ public function delete(Entities\IEntity|int|string $entity): bool { @@ -59,15 +58,19 @@ public function delete(Entities\IEntity|int|string $entity): bool Utils\Arrays::invoke($this->beforeAction, $entity); - $this->entityManager->getConnection()->beginTransaction(); + try { + $this->entityManager->getConnection()->beginTransaction(); - $this->entityManager->remove($entity); + $this->entityManager->remove($entity); - if ($this->getFlush() === true) { - $this->entityManager->flush(); - } + if ($this->getFlush() === true) { + $this->entityManager->flush(); + } - $this->entityManager->getConnection()->commit(); + $this->entityManager->getConnection()->commit(); + } catch (ORM\Exception\ORMException | DBAL\Exception $ex) { + throw new Exceptions\InvalidState('Entity could not be deleted', $ex->getCode(), $ex); + } Utils\Arrays::invoke($this->afterAction); diff --git a/src/Crud/Update/EntityUpdater.php b/src/Crud/Update/EntityUpdater.php index 5f3eae3..4a54b15 100644 --- a/src/Crud/Update/EntityUpdater.php +++ b/src/Crud/Update/EntityUpdater.php @@ -57,9 +57,8 @@ public function __construct( } /** - * @throws DBAL\Exception\UniqueConstraintViolationException * @throws Exceptions\InvalidArgument - * @throws ORM\Exception\ORMException + * @throws Exceptions\InvalidState */ public function update(Utils\ArrayHash $values, Entities\IEntity|int|string $entity): Entities\IEntity { @@ -80,7 +79,11 @@ public function update(Utils\ArrayHash $values, Entities\IEntity|int|string $ent Utils\Arrays::invoke($this->afterAction, $entity, $values); if ($this->getFlush() === true) { - $this->entityManager->flush(); + try { + $this->entityManager->flush(); + } catch (DBAL\Exception\UniqueConstraintViolationException | ORM\Exception\ORMException $ex) { + throw new Exceptions\InvalidState('Entity could not be updated', $ex->getCode(), $ex); + } } return $entity; From 2596174690527660f12ecf45a0be1282d725aa50 Mon Sep 17 00:00:00 2001 From: Adam Kadlec Date: Sun, 4 Aug 2024 23:20:51 +0200 Subject: [PATCH 2/2] Action --- .github/workflows/ci.yaml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2e41c2b..e18c447 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -255,7 +255,14 @@ jobs: run: "${{ env.composer-install }}" - name: "Tests" - run: "make coverage" + run: "make coverage-clover" + + - name: "Upload logs" + uses: "actions/upload-artifact@v3" + with: + name: "Logs - Tests (${{ runner.os }}, ${{ matrix.php-version }})" + path: "var/log" + if-no-files-found: "ignore" - name: "Coveralls.io" env: @@ -263,5 +270,5 @@ jobs: CI: true COVERALLS_REPO_TOKEN: "${{ secrets.GITHUB_TOKEN }}" run: | - wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar - php php-coveralls.phar --verbose --config tests/.coveralls.yml + wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.5.3/php-coveralls.phar + php php-coveralls.phar --verbose --config tools/.coveralls.yml