From 298ebef76af3822657be95109274029e80dddcf0 Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Sun, 11 Oct 2020 12:51:17 +0200 Subject: [PATCH] gactions: add tests --- .github/workflows/build.yml | 93 ++++++++++++++++++++++++++++++++++++- composer.json | 3 +- tests/databases.sample.ini | 4 +- tests/run.sh | 2 +- 4 files changed, 97 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3f69596a..f05152aa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,10 @@ jobs: runs-on: ubuntu-latest + strategy: + matrix: + php-versions: [ '7.4' ] + steps: - name: Checkout uses: actions/checkout@v2 @@ -17,7 +21,7 @@ jobs: - name: Setup PHP with pecl extension uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: ${{ matrix.php-versions }} - name: Get composer cache directory id: composercache @@ -35,3 +39,90 @@ jobs: - name: Run PHPStan run: composer phpstan + + tests: + name: Tests + + strategy: + matrix: + php-versions: [ '7.1', '7.2', '7.3', '7.4' ] + + runs-on: ubuntu-latest + + services: + mysql: + image: mysql:5.7 + env: + MYSQL_DATABASE: nextras_dbal_test + MYSQL_ROOT_PASSWORD: root + ports: + - 3306:3306 + options: >- + --health-cmd "mysqladmin ping -ppass" + --health-interval 10s + --health-start-period 10s + --health-timeout 5s + --health-retries 10 + postgres: + image: postgres:10.8 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: nextras_dbal_test + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP with pecl extension + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, intl, mysqli + coverage: pcov + + - name: Get composer cache directory + id: composercache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composercache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer install --prefer-dist --no-interaction --no-progress --no-suggest + + - name: Init config + run: cp ./tests/databases.sample.ini ./tests/databases.ini && cat ./tests/databases.ini + + - name: Tests + run: ./tests/run.sh ./tests/cases --coverage ./clover.xml --coverage-src ./src + + - name: Send coverage report + env: + COVERALLS_PARALLEL: "true" + COVERALLS_FLAG_NAME: run-${{ matrix.php-versions }} + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + composer require --dev php-coveralls/php-coveralls && \ + vendor/bin/php-coveralls -v --coverage_clover=./clover.xml --json_path=./coveralls-upload.json + + coverage-finish: + needs: tests + runs-on: ubuntu-latest + steps: + - name: Coveralls Finished + env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + curl -k https://coveralls.io/webhook?repo_name=$GITHUB_REPOSITORY&repo_token=$COVERALLS_REPO_TOKEN -d "payload[build_num]=$GITHUB_RUN_ID&payload[status]=done" diff --git a/composer.json b/composer.json index 4e926434..ee9b3923 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,8 @@ "issues": "https://github.com/nextras/dbal/issues" }, "require": { - "php": ">=7.1" + "php": ">=7.1", + "ext-json": "*" }, "require-dev": { "mockery/mockery": "~1.3.0", diff --git a/tests/databases.sample.ini b/tests/databases.sample.ini index bec0e05f..f9d2f984 100644 --- a/tests/databases.sample.ini +++ b/tests/databases.sample.ini @@ -3,11 +3,11 @@ driver = mysqli host = "127.0.0.1" database = nextras_dbal_test username = root -password = +password = root [pgsql] driver = pgsql host = "127.0.0.1" database = nextras_dbal_test username = postgres -password = +password = postgres diff --git a/tests/run.sh b/tests/run.sh index a5a2c5b0..ee5e83b5 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -1,3 +1,3 @@ #!/bin/sh dir=$(cd `dirname $0` && pwd) -$dir/../vendor/bin/tester -p php -c $dir/php.ini --setup $dir/inc/setup.php $@ +$dir/../vendor/bin/tester -C --setup $dir/inc/setup.php $@