Skip to content

Commit

Permalink
Merge pull request #8 from ipublikuj/feature/throw-exception
Browse files Browse the repository at this point in the history
Throw dbal exception
  • Loading branch information
akadlec authored Aug 5, 2024
2 parents 9c64c1e + 2cb5057 commit 40ad506
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 93 deletions.
139 changes: 53 additions & 86 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,32 @@ on:
push:
branches:
- "master"
tags:
- v*
schedule:
- cron: "0 8 * * 1" # At 08:00 on Monday

env:
extensions: "json"
cache-version: "1"
composer-version: "v2"
composer-install: "composer update --no-interaction --no-progress --no-suggest --prefer-dist --prefer-stable"
composer-options: "--no-interaction --no-progress --no-suggest --prefer-dist --prefer-stable"
coverage: "none"

jobs:
qa:
name: "Quality assurance"
name: "Code quality assurance"
runs-on: "${{ matrix.operating-system }}"

strategy:
fail-fast: false
matrix:
php-version: ["8.1"]
php-version: ["8.1","8.2","8.3"]
operating-system: ["ubuntu-latest"]
fail-fast: false

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"

- name: "Setup PHP cache environment"
id: "extcache"
Expand All @@ -41,7 +43,7 @@ jobs:
key: "${{ env.cache-version }}"

- name: "Cache PHP extensions"
uses: "actions/cache@v2"
uses: "actions/cache@v4"
with:
path: "${{ steps.extcache.outputs.dir }}"
key: "${{ steps.extcache.outputs.key }}"
Expand All @@ -53,44 +55,34 @@ jobs:
php-version: "${{ matrix.php-version }}"
extensions: "${{ env.extensions }}"
tools: "composer:${{ env.composer-version }}, cs2pr"
coverage: "${{ env.coverage }}"
coverage: "none"

- name: "Setup problem matchers for PHP"
run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"'

- name: "Get Composer cache directory"
id: "composercache"
run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"'

- name: "Cache PHP dependencies"
uses: "actions/cache@v2"
- name: "Setup composer & install dependencies"
uses: "ramsey/composer-install@v2"
with:
path: "${{ steps.composercache.outputs.dir }}"
key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"
restore-keys: "${{ runner.os }}-composer-"

- name: "Validate Composer"
run: "composer validate"

- name: "Install dependencies"
run: "${{ env.composer-install }}"
dependency-versions: "highest"
composer-options: "${{ env.composer-options }}"
custom-cache-key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"

- name: "Coding Standard"
run: "make cs"

static-analysis:
name: "Static analysis"
name: "Code static analysis"
runs-on: "${{ matrix.operating-system }}"

strategy:
fail-fast: false
matrix:
php-version: ["8.1"]
php-version: ["8.1","8.2","8.3"]
operating-system: ["ubuntu-latest"]
fail-fast: false

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"

- name: "Setup PHP cache environment"
id: "extcache"
Expand All @@ -101,7 +93,7 @@ jobs:
key: "${{ env.cache-version }}"

- name: "Cache PHP extensions"
uses: "actions/cache@v2"
uses: "actions/cache@v4"
with:
path: "${{ steps.extcache.outputs.dir }}"
key: "${{ steps.extcache.outputs.key }}"
Expand All @@ -118,36 +110,30 @@ jobs:
- name: "Setup problem matchers for PHP"
run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"'

- name: "Get Composer cache directory"
id: "composercache"
run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"'

- name: "Cache PHP dependencies"
uses: "actions/cache@v2"
- name: "Setup composer & install dependencies"
uses: "ramsey/composer-install@v2"
with:
path: "${{ steps.composercache.outputs.dir }}"
key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"
restore-keys: "${{ runner.os }}-composer-"

- name: "Install dependencies"
run: "${{ env.composer-install }}"
dependency-versions: "highest"
composer-options: "${{ env.composer-options }}"
custom-cache-key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"

- name: "PHPStan"
run: "make phpstan"

tests:
name: "Tests"
name: "Code tests"
runs-on: "${{ matrix.operating-system }}"
needs: ["qa", "static-analysis"]

strategy:
fail-fast: false
matrix:
php-version: ["8.1"]
php-version: ["8.1","8.2","8.3"]
operating-system: ["ubuntu-latest"]
fail-fast: false

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"

- name: "Setup PHP cache environment"
id: "extcache"
Expand All @@ -158,7 +144,7 @@ jobs:
key: "${{ env.cache-version }}"

- name: "Cache PHP extensions"
uses: "actions/cache@v2"
uses: "actions/cache@v4"
with:
path: "${{ steps.extcache.outputs.dir }}"
key: "${{ steps.extcache.outputs.key }}"
Expand All @@ -175,45 +161,39 @@ jobs:
- name: "Setup problem matchers for PHP"
run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"'

- name: "Get Composer cache directory"
id: "composercache"
run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"'

- name: "Cache PHP dependencies"
uses: "actions/cache@v2"
- name: "Setup composer & install dependencies"
uses: "ramsey/composer-install@v2"
with:
path: "${{ steps.composercache.outputs.dir }}"
key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"
restore-keys: "${{ runner.os }}-composer-"

- name: "Install dependencies"
run: "${{ env.composer-install }} ${{ matrix.composer-args }}"
dependency-versions: "highest"
composer-options: "${{ env.composer-options }}"
custom-cache-key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"

- name: "Tests"
run: "make tests"

- name: "Upload test output"
if: ${{ failure() }}
uses: actions/upload-artifact@v2
- name: "Upload logs"
uses: "actions/upload-artifact@v4"
with:
name: output
path: tests/**/output
name: "Logs - Tests (${{ matrix.operating-system }}, ${{ matrix.php-version }})"
path: "var/log"
if-no-files-found: "ignore"

tests-code-coverage:
name: "Tests with code coverage"
name: "Code tests with code coverage"
runs-on: "${{ matrix.operating-system }}"
needs: ["tests"]

strategy:
matrix:
php-version: ["8.1"]
php-version: ["8.1","8.2","8.3"]
operating-system: ["ubuntu-latest"]
fail-fast: false

if: "github.event_name == 'push'"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"

- name: "Setup PHP cache environment"
id: "extcache"
Expand All @@ -224,7 +204,7 @@ jobs:
key: "${{ env.cache-version }}"

- name: "Cache PHP extensions"
uses: "actions/cache@v2"
uses: "actions/cache@v4"
with:
path: "${{ steps.extcache.outputs.dir }}"
key: "${{ steps.extcache.outputs.key }}"
Expand All @@ -235,40 +215,27 @@ jobs:
with:
php-version: "${{ matrix.php-version }}"
extensions: "${{ env.extensions }}"
tools: "composer:${{ env.composer-version }} "
tools: "composer:${{ env.composer-version }}"
coverage: "pcov"

- name: "Setup problem matchers for PHP"
run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"'

- name: "Get Composer cache directory"
id: "composercache"
run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"'

- name: "Cache PHP dependencies"
uses: "actions/cache@v2"
- name: "Setup composer & install dependencies"
uses: "ramsey/composer-install@v2"
with:
path: "${{ steps.composercache.outputs.dir }}"
key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"
restore-keys: "${{ runner.os }}-composer-"

- name: "Install dependencies"
run: "${{ env.composer-install }}"
dependency-versions: "highest"
composer-options: "${{ env.composer-options }}"
custom-cache-key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"

- name: "Tests"
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 }}"
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
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
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Doctrine CRUD

[![Build Status](https://badgen.net/github/checks/ipublikuj/doctrine-crud/master?cache=300&style=flast-square)](https://github.com/ipublikuj/doctrine-crud)
[![Code coverage](https://badgen.net/coveralls/c/github/ipublikuj/doctrine-crud?cache=300&style=flast-square)](https://coveralls.io/github/ipublikuj/doctrine-crud)
[![Build Status](https://badgen.net/github/checks/ipublikuj/doctrine-crud/master?cache=300&style=flast-square)](https://github.com/ipublikuj/doctrine-crud/actions)
[![Licence](https://badgen.net/github/license/ipublikuj/doctrine-crud?cache=300&style=flast-square)](https://github.com/ipublikuj/doctrine-crud/blob/master/LICENSE.md)
[![Code coverage](https://badgen.net/coveralls/c/github/ipublikuj/doctrine-crud?cache=300&style=flast-square)](https://coveralls.io/r/ipublikuj/doctrine-crud)

![PHP](https://badgen.net/packagist/php/ipub/doctrine-crud?cache=300&style=flast-square)
[![Licence](https://badgen.net/packagist/license/ipub/doctrine-crud?cache=300&style=flast-square)](https://github.com/ipublikuj/doctrine-crud/blob/master/LICENSE.md)
[![Downloads total](https://badgen.net/packagist/dt/ipub/doctrine-crud?cache=300&style=flast-square)](https://packagist.org/packages/ipub/doctrine-crud)
[![Latest stable](https://badgen.net/packagist/v/ipub/doctrine-crud/latest?cache=300&style=flast-square)](https://packagist.org/packages/ipub/doctrine-crud)
[![Latest stable](https://badgen.net/packagist/v/ipub/doctrine-crud/latest?cache=300&style=flast-square)](https://packagist.org/packages/ipublikuj/doctrine-crud)
[![Downloads total](https://badgen.net/packagist/dt/ipub/doctrine-crud?cache=300&style=flast-square)](https://packagist.org/packages/ipublikuj/doctrine-crud)
[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-brightgreen.svg?style=flat-square)](https://github.com/phpstan/phpstan)

Implementation of CRUD system into [Doctrine3](https://github.com/doctrine/orm) with CRUD system.
Expand Down
3 changes: 2 additions & 1 deletion src/Crud/Create/EntityCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function __construct(
}

/**
* @throws DBAL\Exception\UniqueConstraintViolationException
* @throws Exceptions\EntityCreation
* @throws Exceptions\InvalidArgument
* @throws Exceptions\InvalidState
Expand Down Expand Up @@ -121,7 +122,7 @@ public function create(Utils\ArrayHash $values, Entities\IEntity|null $entity =
if ($this->getFlush()) {
try {
$this->entityManager->flush();
} catch (DBAL\Exception\UniqueConstraintViolationException | ORM\Exception\ORMException $ex) {
} catch (ORM\Exception\ORMException $ex) {
throw new Exceptions\InvalidState('Entity could not be created', $ex->getCode(), $ex);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Crud/Update/EntityUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function __construct(
}

/**
* @throws DBAL\Exception\UniqueConstraintViolationException
* @throws Exceptions\InvalidArgument
* @throws Exceptions\InvalidState
*/
Expand All @@ -81,7 +82,7 @@ public function update(Utils\ArrayHash $values, Entities\IEntity|int|string $ent
if ($this->getFlush() === true) {
try {
$this->entityManager->flush();
} catch (DBAL\Exception\UniqueConstraintViolationException | ORM\Exception\ORMException $ex) {
} catch (ORM\Exception\ORMException $ex) {
throw new Exceptions\InvalidState('Entity could not be updated', $ex->getCode(), $ex);
}
}
Expand Down

0 comments on commit 40ad506

Please sign in to comment.