Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override exceptions #7

Merged
merged 2 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,20 @@ 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:
CI_NAME: github
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
8 changes: 5 additions & 3 deletions src/Crud/Create/EntityCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 11 additions & 8 deletions src/Crud/Delete/EntityDeleter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);

Expand Down
9 changes: 6 additions & 3 deletions src/Crud/Update/EntityUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
Expand Down
Loading