From e3f1e2b136761e42b34941957123ed0305c2c0a6 Mon Sep 17 00:00:00 2001 From: Petr Parolek Date: Sun, 17 Jan 2021 15:36:24 +0100 Subject: [PATCH] Maintenance: codeception, github actions, phpstan, coveralls --- .github/workflows/main.yaml | 291 +++++++++++++++++++++++++++++++ .travis.yml | 41 ----- Makefile | 28 +++ codeception.yml | 28 ++- composer.json | 31 ++-- phpstan.neon | 4 + run-tests.sh | 3 - src/Calculators/BcCalculator.php | 1 + src/Components/Paginator.php | 1 + src/Renderers/PDFRenderer.php | 1 + 10 files changed, 361 insertions(+), 68 deletions(-) create mode 100644 .github/workflows/main.yaml delete mode 100644 .travis.yml create mode 100644 Makefile create mode 100644 phpstan.neon delete mode 100755 run-tests.sh diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..fa52e07 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,291 @@ +name: "build" + +on: + pull_request: + paths-ignore: + - ".docs/**" + push: + branches: + - "master" + 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 --prefer-dist --prefer-stable" + coverage: "none" + +jobs: + qa: + name: "Quality assurance" + runs-on: "${{ matrix.operating-system }}" + + strategy: + matrix: + php-version: ["7.4"] + operating-system: ["ubuntu-latest"] + fail-fast: false + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Setup PHP cache environment" + id: "extcache" + uses: "shivammathur/cache-extensions@v1" + with: + php-version: "${{ matrix.php-version }}" + extensions: "${{ env.extensions }}" + key: "${{ env.cache-version }}" + + - name: "Cache PHP extensions" + uses: "actions/cache@v2" + with: + path: "${{ steps.extcache.outputs.dir }}" + key: "${{ steps.extcache.outputs.key }}" + restore-keys: "${{ steps.extcache.outputs.key }}" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + extensions: "${{ env.extensions }}" + tools: "composer:${{ env.composer-version }}, cs2pr" + coverage: "${{ env.coverage }}" + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - 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" + 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 }}" + + - name: "Coding Standard" + run: "make cs" + + static-analysis: + name: "Static analysis" + runs-on: "${{ matrix.operating-system }}" + + strategy: + matrix: + php-version: ["7.4"] + operating-system: ["ubuntu-latest"] + fail-fast: false + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Setup PHP cache environment" + id: "extcache" + uses: "shivammathur/cache-extensions@v1" + with: + php-version: "${{ matrix.php-version }}" + extensions: "${{ env.extensions }}" + key: "${{ env.cache-version }}" + + - name: "Cache PHP extensions" + uses: "actions/cache@v2" + with: + path: "${{ steps.extcache.outputs.dir }}" + key: "${{ steps.extcache.outputs.key }}" + restore-keys: "${{ steps.extcache.outputs.key }}" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + extensions: "${{ env.extensions }}" + tools: "composer:${{ env.composer-version }}" + coverage: "${{ env.coverage }}" + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - 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" + 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 }}" + + - name: "PHPStan" + run: "make phpstan" + + tests: + name: "Tests" + runs-on: "${{ matrix.operating-system }}" + + strategy: + matrix: + php-version: ["7.2", "7.3", "7.4"] + operating-system: ["ubuntu-latest"] + composer-args: [ "" ] + include: + - php-version: "7.2" + operating-system: "ubuntu-latest" + composer-args: "--prefer-lowest" + - php-version: "8.0" + operating-system: "ubuntu-latest" + composer-args: "" + fail-fast: false + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Setup PHP cache environment" + id: "extcache" + uses: "shivammathur/cache-extensions@v1" + with: + php-version: "${{ matrix.php-version }}" + extensions: "${{ env.extensions }}" + key: "${{ env.cache-version }}" + + - name: "Cache PHP extensions" + uses: "actions/cache@v2" + with: + path: "${{ steps.extcache.outputs.dir }}" + key: "${{ steps.extcache.outputs.key }}" + restore-keys: "${{ steps.extcache.outputs.key }}" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + extensions: "${{ env.extensions }}" + tools: "composer:${{ env.composer-version }}" + coverage: "${{ env.coverage }}" + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - 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" + 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 }}" + + - name: "Tests" + run: "make tests" + + - name: "Upload test output" + if: ${{ failure() }} + uses: actions/upload-artifact@v2 + with: + name: output + path: tests/**/output + + tests-code-coverage: + name: "Tests with code coverage" + runs-on: "${{ matrix.operating-system }}" + + strategy: + matrix: + php-version: ["7.4"] + operating-system: ["ubuntu-latest"] + fail-fast: false + + if: "github.event_name == 'push'" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Setup PHP cache environment" + id: "extcache" + uses: "shivammathur/cache-extensions@v1" + with: + php-version: "${{ matrix.php-version }}" + extensions: "${{ env.extensions }}" + key: "${{ env.cache-version }}" + + - name: "Cache PHP extensions" + uses: "actions/cache@v2" + with: + path: "${{ steps.extcache.outputs.dir }}" + key: "${{ steps.extcache.outputs.key }}" + restore-keys: "${{ steps.extcache.outputs.key }}" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + extensions: "${{ env.extensions }}" + tools: "composer:${{ env.composer-version }}" + coverage: "${{ env.coverage }}" + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - 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" + 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 }}" + + - name: "Tests" + run: "make coverage-clover" + + - name: "Upload test output" + if: ${{ failure() }} + uses: actions/upload-artifact@v2 + with: + name: output + path: tests/**/output + + - name: "Coveralls.io" + env: + CI_NAME: github + CI: true + COVERALLS_REPO_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + run: | + composer global require php-coveralls/php-coveralls + php-coveralls --coverage_clover=tests/_output/coverage.xml --json_path=coveralls-upload.json -v diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 80e7fce..0000000 --- a/.travis.yml +++ /dev/null @@ -1,41 +0,0 @@ -language: php -php: - - 7.2 - - 7.3 - -before_install: - # Turn off XDebug - - phpenv config-rm xdebug.ini || return 0 - -install: - # Composer - - travis_retry composer install --no-progress --prefer-dist -script: - # Tests - - composer run-script tests - -jobs: - include: - - env: title="Lowest Dependencies 7.2" - php: 7.2 - install: - - travis_retry composer update --no-progress --prefer-dist --prefer-lowest - script: - - composer run-script tests - - - stage: Quality Assurance - php: 7.2 - script: - - composer run-script qa - - - stage: PHPStan - php: 7.2 - script: - - composer run-script phpstan-install - - composer run-script phpstan - -sudo: false - -cache: - directories: - - $HOME/.composer/cache diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2542edb --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +.PHONY: install qa cs csf phpstan tests coverage-clover coverage-html + +install: + composer update + +qa: phpstan cs + +cs: +ifdef GITHUB_ACTION + vendor/bin/codesniffer -q --report=checkstyle src tests | cs2pr +else + vendor/bin/codesniffer src tests +endif + +csf: + vendor/bin/codefixer src tests + +phpstan: + vendor/bin/phpstan analyse -l max -c phpstan.neon src + +tests: + vendor/bin/codecept run + +coverage-clover: + phpdbg -qrr vendor/bin/codecept run --coverage-xml + +coverage-html: + phpdbg -qrr vendor/bin/codecept run --coverage-html diff --git a/codeception.yml b/codeception.yml index f0446cc..4addacf 100644 --- a/codeception.yml +++ b/codeception.yml @@ -1,10 +1,26 @@ +actor: Tester + paths: - tests: tests - output: tests/_output - data: tests/_data - support: tests/_support - envs: tests/_envs -actor_suffix: Tester + # where the tests stored + tests: tests + + # directory for fixture data + data: tests/_data + + # directory for support code + support: tests/_support + + # directory for output + output: tests/_output + extensions: enabled: - Codeception\Extension\RunFailed + +settings: + log: true + +coverage: + enabled: true + include: + - src/** diff --git a/composer.json b/composer.json index f2792bc..829a6ff 100755 --- a/composer.json +++ b/composer.json @@ -3,21 +3,26 @@ "type": "library", "description": "Library for easily and quickly creating invoices for customers.", "license": ["MIT"], - "tags": [ + "keywords": [ "contributte", "invoice" ], "require": { "php": ">=7.2", - "nette/utils": "^3.0", - "setasign/fpdf": "^1.8" + "nette/utils": "^3.0.0", + "setasign/fpdf": "^1.8.0" }, "require-dev": { - "ninjify/qa": "^0.8.0", - "ninjify/nunjuck": "^0.2.0", - "nette/di": "^3.0", - "nette/application": "^3.0", - "codeception/codeception": "^2.4" + "codeception/codeception": "^4.1.0", + "codeception/module-asserts": "^1.3.0", + "codeception/module-phpbrowser": "^1.0.0", + "nette/di": "^3.0.0", + "nette/application": "^3.0.0", + "ninjify/qa": "^0.12.0", + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-deprecation-rules": "^0.12", + "phpstan/phpstan-nette": "^0.12" + }, "autoload": { "psr-4": { @@ -31,16 +36,6 @@ ], "tests": [ "vendor/bin/codecept run" - ], - "phpstan-install": [ - "mkdir -p temp/phpstan", - "composer require -d temp/phpstan phpstan/phpstan:^0.12", - "composer require -d temp/phpstan phpstan/extension-installer:^1.0.4", - "composer require -d temp/phpstan phpstan/phpstan-deprecation-rules:^0.12", - "composer require -d temp/phpstan phpstan/phpstan-nette:^0.12" - ], - "phpstan": [ - "temp/phpstan/vendor/bin/phpstan analyse -l max src" ] }, "minimum-stability": "RC", diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..a89119f --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,4 @@ +includes: + - vendor/phpstan/phpstan-deprecation-rules/rules.neon + - vendor/phpstan/phpstan-nette/extension.neon + - vendor/phpstan/phpstan-nette/rules.neon diff --git a/run-tests.sh b/run-tests.sh deleted file mode 100755 index ac8d925..0000000 --- a/run-tests.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/sh - -vendor/bin/phpstan analyse src --level=7 diff --git a/src/Calculators/BcCalculator.php b/src/Calculators/BcCalculator.php index 6a34bcd..171f36b 100644 --- a/src/Calculators/BcCalculator.php +++ b/src/Calculators/BcCalculator.php @@ -15,6 +15,7 @@ public function __construct(int $scale = 0) if (!function_exists('bcadd')) { throw new RuntimeException('BC math is not installed.'); } + $this->scale = $scale; } diff --git a/src/Components/Paginator.php b/src/Components/Paginator.php index a314ad3..1aa5bc5 100755 --- a/src/Components/Paginator.php +++ b/src/Components/Paginator.php @@ -67,6 +67,7 @@ public function nextPage(): bool if ($this->isLastPage()) { return false; } + $this->currentPage++; return true; diff --git a/src/Renderers/PDFRenderer.php b/src/Renderers/PDFRenderer.php index 4e8df98..ec1aec0 100644 --- a/src/Renderers/PDFRenderer.php +++ b/src/Renderers/PDFRenderer.php @@ -137,6 +137,7 @@ protected function setDrawing(Settings $settings): void $this->pdf->SetDrawColor($color->getRed(), $color->getGreen(), $color->getBlue()); } + if ($settings->fillColor !== null) { $color = $settings->fillColor;