Skip to content

Commit e859354

Browse files
authored
Added workflow CI for check suite (#2)
Added CI for GitHub Actions. Added tests. Added bash-script for launch tests locally.
1 parent 695a804 commit e859354

40 files changed

+1714
-53
lines changed

.github/workflows/ci.yml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- '*'
7+
pull_request:
8+
schedule:
9+
- cron: '0 0 * * *'
10+
11+
env:
12+
php_extensions: 'apcu, bcmath, ctype, curl, dom, iconv, intl, json, mbstring, opcache, openssl, pdo, pdo_pgsql, pcntl, pcov, posix, redis, session, simplexml, sockets, tokenizer, xml, xmlwriter, zip'
13+
key: cache-v0.1
14+
DB_USER: 'postgres'
15+
DB_NAME: 'testing'
16+
DB_PASSWORD: 'postgres'
17+
18+
jobs:
19+
lint:
20+
runs-on: '${{ matrix.operating_system }}'
21+
timeout-minutes: 20
22+
strategy:
23+
matrix:
24+
operating_system: [ubuntu-latest]
25+
php_versions: ['7.4']
26+
fail-fast: false
27+
env:
28+
PHP_CS_FIXER_FUTURE_MODE: '0'
29+
name: 'Lint PHP'
30+
steps:
31+
- name: 'Checkout'
32+
uses: actions/checkout@v2
33+
- name: 'Setup cache environment'
34+
id: cache-env
35+
uses: shivammathur/cache-extensions@v1
36+
with:
37+
php-version: '${{ matrix.php_versions }}'
38+
extensions: '${{ env.php_extensions }}'
39+
key: '${{ env.key }}'
40+
- name: 'Cache extensions'
41+
uses: actions/cache@v1
42+
with:
43+
path: '${{ steps.cache-env.outputs.dir }}'
44+
key: '${{ steps.cache-env.outputs.key }}'
45+
restore-keys: '${{ steps.cache-env.outputs.key }}'
46+
- name: 'Setup PHP'
47+
uses: shivammathur/setup-php@v2
48+
with:
49+
php-version: ${{ matrix.php_versions }}
50+
extensions: '${{ env.php_extensions }}'
51+
ini-values: memory_limit=-1
52+
tools: pecl, composer
53+
coverage: none
54+
- name: 'Setup problem matchers for PHP (aka PHP error logs)'
55+
run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"'
56+
- name: 'Setup problem matchers for PHPUnit'
57+
run: 'echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"'
58+
- name: 'Install PHP dependencies with Composer'
59+
run: composer install --prefer-dist --no-progress --no-suggest --optimize-autoloader
60+
working-directory: './'
61+
- name: 'Linting PHP source files'
62+
run: 'vendor/bin/ecs check --config=ecs.yml .'
63+
test:
64+
strategy:
65+
fail-fast: false
66+
matrix:
67+
coverage: [false]
68+
experimental: [false]
69+
operating_system: [ubuntu-latest]
70+
postgres: ['11']
71+
laravel: ['^6.0', '^7.0', '^8.0']
72+
php_versions: ['7.3', '7.4']
73+
include:
74+
- operating_system: ubuntu-latest
75+
postgres: '11'
76+
php_versions: '7.4'
77+
experimental: false
78+
laravel: '^8.0'
79+
coverage: true
80+
- operating_system: ubuntu-latest
81+
postgres: '12'
82+
php_versions: '8.0'
83+
laravel: '^8.0'
84+
experimental: true
85+
coverage: false
86+
runs-on: '${{ matrix.operating_system }}'
87+
services:
88+
postgres:
89+
image: 'postgres:${{ matrix.postgres }}'
90+
env:
91+
POSTGRES_USER: ${{ env.DB_USER }}
92+
POSTGRES_PASSWORD: ${{ env.DB_PASSWORD }}
93+
POSTGRES_DB: ${{ env.DB_NAME }}
94+
ports:
95+
- 5432:5432
96+
# needed because the postgres container does not provide a healthcheck
97+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
98+
name: 'Test / Laravel ${{ matrix.laravel }} / PHP ${{ matrix.php_versions }} / Postgres ${{ matrix.postgres }}'
99+
needs:
100+
- lint
101+
steps:
102+
- name: 'Checkout'
103+
uses: actions/checkout@v2
104+
with:
105+
fetch-depth: 1
106+
- name: 'Install postgres client'
107+
run: |
108+
sudo apt-get update -y
109+
sudo apt-get install -y libpq-dev postgresql-client
110+
- name: 'Setup cache environment'
111+
id: cache-env
112+
uses: shivammathur/cache-extensions@v1
113+
with:
114+
php-version: ${{ matrix.php_versions }}
115+
extensions: ${{ env.php_extensions }}
116+
key: '${{ env.key }}'
117+
- name: 'Cache extensions'
118+
uses: actions/cache@v1
119+
with:
120+
path: '${{ steps.cache-env.outputs.dir }}'
121+
key: '${{ steps.cache-env.outputs.key }}'
122+
restore-keys: '${{ steps.cache-env.outputs.key }}'
123+
- name: 'Setup PHP'
124+
uses: shivammathur/setup-php@v2
125+
with:
126+
php-version: ${{ matrix.php_versions }}
127+
extensions: ${{ env.php_extensions }}
128+
ini-values: 'pcov.directory=src, date.timezone=UTC, upload_max_filesize=20M, post_max_size=20M, memory_limit=512M, short_open_tag=Off'
129+
coverage: pcov
130+
tools: 'phpunit'
131+
- name: 'Install PHP dependencies with Composer'
132+
run: |
133+
composer require "laravel/framework=${{ matrix.laravel }}" --no-update
134+
composer install --prefer-dist --no-progress --no-suggest --optimize-autoloader
135+
working-directory: './'
136+
- name: 'Run Unit Tests with PHPUnit'
137+
continue-on-error: ${{ matrix.experimental }}
138+
env:
139+
POSTGRES_USER: ${{ env.DB_USER }}
140+
POSTGRES_PASSWORD: ${{ env.DB_PASSWORD }}
141+
POSTGRES_DB: ${{ env.DB_NAME }}
142+
POSTGRES_HOST: 127.0.0.1
143+
POSTGRES_PORT: 5432
144+
run: |
145+
if [[ ${{ matrix.coverage }} == true ]]; then
146+
./vendor/bin/phpunit --verbose --stderr --configuration phpunit.github.xml --coverage-clover build/logs/clover.xml --coverage-text
147+
else
148+
./vendor/bin/phpunit --verbose --stderr --configuration phpunit.github.xml
149+
fi
150+
working-directory: './'
151+
- name: 'Upload coverage results to Coveralls'
152+
if: ${{ !matrix.experimental && matrix.coverage }}
153+
env:
154+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
155+
COVERALLS_PARALLEL: true
156+
COVERALLS_FLAG_NAME: php-${{ matrix.php_versions }}-postgres-${{ matrix.postgres }}
157+
run: ./vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v
158+
coverage:
159+
needs: test
160+
runs-on: ubuntu-latest
161+
name: "Code coverage"
162+
steps:
163+
- name: 'Coveralls Finished'
164+
uses: coverallsapp/github-action@v1.1.2
165+
with:
166+
github-token: ${{ secrets.GITHUB_TOKEN }}
167+
parallel-finished: true

composer.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"license": "MIT",
1414
"type": "library",
1515
"require": {
16-
"php": "^7.2|^7.3|^7.4|^8.0",
16+
"php": "^7.3|^7.4|^8.0",
1717
"ext-json": "*",
1818
"php-amqplib/php-amqplib": "^2.8",
1919
"laravel/framework": "^5.8|^6.0|^7.0|^8.0",
@@ -29,7 +29,10 @@
2929
"orchestra/testbench": "^3.8|^4.8|^5.7|^6.2",
3030
"mockery/mockery": "^1.0",
3131
"mikey179/vfsstream": "^1.6",
32-
"umbrellio/code-style-php": "^1.0"
32+
"umbrellio/code-style-php": "^1.0",
33+
"laravel/legacy-factories": "*",
34+
"php-coveralls/php-coveralls": "^2.1",
35+
"squizlabs/php_codesniffer": "^3.5"
3336
},
3437
"authors": [
3538
{
@@ -41,6 +44,10 @@
4144
"email": "pvsaintpe@icloud.com"
4245
}
4346
],
47+
"support": {
48+
"issues": "https://github.com/umbrellio/table_sync_php/issues",
49+
"source": "https://github.com/umbrellio/table_sync_php"
50+
},
4451
"minimum-stability": "stable",
4552
"autoload": {
4653
"psr-4": {
@@ -54,10 +61,10 @@
5461
},
5562
"scripts": {
5663
"lint-fix":[
57-
"vendor/bin/ecs check src tests -c easy-coding-standard.yml --fix"
64+
"vendor/bin/ecs check src tests -c ecs.yml --fix"
5865
],
5966
"test":[
60-
"vendor/bin/phpunit --colors=never"
67+
"vendor/bin/phpunit"
6168
]
6269
},
6370
"extra": {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Faker\Generator as Faker;
6+
use Umbrellio\TableSync\Tests\functional\Laravel\Models\SoftTestModel;
7+
8+
$factory->define(SoftTestModel::class, function (Faker $faker) {
9+
return [
10+
'name' => $faker->name,
11+
];
12+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Faker\Generator as Faker;
6+
use Umbrellio\TableSync\Tests\functional\Laravel\Models\TestModel;
7+
use Umbrellio\TableSync\Tests\functional\Laravel\Models\TestModelWithExceptedFields;
8+
9+
$factory->define(TestModel::class, function (Faker $faker) {
10+
return [
11+
'name' => $faker->name,
12+
'some_field' => $faker->word,
13+
];
14+
});
15+
16+
$factory->define(TestModelWithExceptedFields::class, function (Faker $faker) use ($factory) {
17+
return $factory->raw(TestModel::class);
18+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\DB;
8+
use Illuminate\Support\Facades\Schema;
9+
10+
class CreateTestModelTable extends Migration
11+
{
12+
public function up()
13+
{
14+
DB::transaction(function () {
15+
Schema::create('test_models', function (Blueprint $table) {
16+
$table->increments('id');
17+
18+
$table->string('name');
19+
$table->string('some_field');
20+
$table->float('version')->default(0.0);
21+
});
22+
23+
Schema::create('soft_test_models', function (Blueprint $table) {
24+
$table->increments('id');
25+
$table->softDeletes();
26+
27+
$table->string('name');
28+
});
29+
});
30+
}
31+
32+
public function down()
33+
{
34+
DB::transaction(function () {
35+
Schema::drop('test_models');
36+
Schema::drop('soft_test_models');
37+
});
38+
}
39+
}

ecs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ parameters:
1212
cache_directory: .ecs_cache
1313
exclude_files:
1414
- vendor/*
15+
- database/*

phpunit.github.xml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
bootstrap="vendor/autoload.php"
34
colors="true"
45
convertErrorsToExceptions="true"
5-
convertNoticesToExceptions="false"
6-
convertWarningsToExceptions="false"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
78
processIsolation="false"
8-
stopOnFailure="false">
9+
stopOnFailure="true"
10+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
11+
>
12+
<coverage processUncoveredFiles="true">
13+
<include>
14+
<directory suffix=".php">./src</directory>
15+
</include>
16+
</coverage>
917
<php>
18+
<env name="APP_ENV" value="testing"/>
1019
<ini name="error_reporting" value="-1" />
1120
<var name="db_type" value="pdo_pgsql"/>
1221
<var name="db_host" value="postgres" />
@@ -20,12 +29,4 @@
2029
<directory suffix="Test.php">./tests</directory>
2130
</testsuite>
2231
</testsuites>
23-
<filter>
24-
<whitelist processUncoveredFilesFromWhitelist="true">
25-
<directory suffix=".php">./src</directory>
26-
<exclude>
27-
<file>./src/.meta.php</file>
28-
</exclude>
29-
</whitelist>
30-
</filter>
3132
</phpunit>

phpunit.xml.dist

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
bootstrap="vendor/autoload.php"
34
colors="true"
45
convertErrorsToExceptions="true"
56
convertNoticesToExceptions="true"
67
convertWarningsToExceptions="true"
78
processIsolation="false"
8-
stopOnFailure="true">
9-
<php>
10-
<var name="db_type" value="pdo_pgsql"/>
11-
<var name="db_host" value="localhost" />
12-
<var name="db_username" value="postgres" />
13-
<var name="db_password" value="" />
14-
<var name="db_database" value="testing" />
15-
<var name="db_port" value="5432"/>
16-
</php>
17-
<filter>
18-
<whitelist processUncoveredFilesFromWhitelist="true">
19-
<directory suffix=".php">./src</directory>
20-
</whitelist>
21-
</filter>
22-
<testsuites>
23-
<testsuite name="Test suite">
24-
<directory suffix="Test.php">./tests</directory>
25-
</testsuite>
26-
</testsuites>
9+
stopOnFailure="true"
10+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
11+
>
12+
<coverage processUncoveredFiles="true">
13+
<include>
14+
<directory suffix=".php">./src</directory>
15+
</include>
16+
</coverage>
17+
<php>
18+
<var name="db_type" value="pdo_pgsql"/>
19+
<var name="db_host" value="localhost"/>
20+
<var name="db_username" value="postgres"/>
21+
<var name="db_password" value=""/>
22+
<var name="db_database" value="testing"/>
23+
<var name="db_port" value="5432"/>
24+
</php>
25+
<testsuites>
26+
<testsuite name="Test suite">
27+
<directory suffix="Test.php">./tests</directory>
28+
</testsuite>
29+
</testsuites>
2730
</phpunit>

src/Integration/Laravel/Console/Commands/RestartCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ public function handle(): void
1616
if (!$this->pidManager->pidExists()) {
1717
$this->info('Table sync worker not started.');
1818
} else {
19-
$arguments = $this->option('force') ? ['--force' => true] : [];
19+
$arguments = $this->option('force') ? [
20+
'--force' => true,
21+
] : [];
2022

2123
$this->call('table_sync:terminate', $arguments);
2224
}

src/Integration/Laravel/Console/ProcessManagerCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ abstract class ProcessManagerCommand extends Command
1313
public function __construct(PidManager $pidManager)
1414
{
1515
parent::__construct();
16+
1617
$this->pidManager = $pidManager;
1718
}
1819
}

0 commit comments

Comments
 (0)