Skip to content

Commit bb5cfc1

Browse files
authored
added github workflow for builds and tests (#318)
* added github workflow for builds and tests Signed-off-by: Fenn-CS <[email protected]> * dynamized database connection details to enable smooth connection in ci environment Signed-off-by: Fenn-CS <[email protected]>
1 parent 2a7b72e commit bb5cfc1

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

.github/workflows/ci.yml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: phpList Build
2+
on: [push, pull_request]
3+
jobs:
4+
main:
5+
name: phpList on PHP ${{ matrix.php-versions }} [Build, Test]
6+
runs-on: ubuntu-latest
7+
env:
8+
DB_DATABASE: phplist
9+
DB_USERNAME: root
10+
DB_PASSWORD: phplist
11+
BROADCAST_DRIVER: log
12+
services:
13+
mysql:
14+
image: mysql:5.7
15+
env:
16+
MYSQL_ALLOW_EMPTY_PASSWORD: false
17+
MYSQL_ROOT_PASSWORD: ${{ env.DB_PASSWORD }}
18+
MYSQL_DATABASE: ${{ env.DB_DATABASE }}
19+
ports:
20+
- 3306/tcp
21+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4']
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v2
29+
- name: Setup PHP, with composer and extensions
30+
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
31+
with:
32+
php-version: ${{ matrix.php-versions }}
33+
extensions: mbstring, dom, fileinfo, mysql
34+
coverage: xdebug #optional
35+
- name: Start mysql service
36+
run: sudo /etc/init.d/mysql start
37+
- name: Verify MySQL connection on host
38+
run: mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -u${{ env.DB_USERNAME }} -p${{ env.DB_PASSWORD }} -e "SHOW DATABASES"
39+
- name: Set up database schema
40+
run: mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -u${{ env.DB_USERNAME }} -p${{ env.DB_PASSWORD }} ${{ env.DB_DATABASE }} < resources/Database/Schema.sql
41+
- name: Get composer cache directory
42+
id: composer-cache
43+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
44+
- name: Cache composer dependencies
45+
uses: actions/cache@v2
46+
with:
47+
path: ${{ steps.composer-cache.outputs.dir }}
48+
# Use composer.json for key, if composer.lock is not committed.
49+
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
50+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
51+
restore-keys: ${{ runner.os }}-composer-
52+
- name: Install Composer dependencies
53+
run: composer install --no-progress --prefer-dist --optimize-autoloader
54+
- name: Validating composer.json
55+
run: composer validate --no-check-all --no-check-lock --strict;
56+
- name: Linting all php files
57+
run: find src/ tests/ public/ -name ''*.php'' -print0 | xargs -0 -n 1 -P 4 php -l; php -l bin/*;
58+
- name: Run units tests with phpunit
59+
run: vendor/bin/phpunit tests/Unit/
60+
- name: Run integration tests with phpunit
61+
run: |
62+
export PHPLIST_DATABASE_NAME=${{ env.DB_DATABASE }}
63+
export PHPLIST_DATABASE_USER=${{ env.DB_USERNAME }}
64+
export PHPLIST_DATABASE_PASSWORD=${{ env.DB_PASSWORD }}
65+
export PHPLIST_DATABASE_PORT=${{ job.services.mysql.ports['3306'] }}
66+
export PHPLIST_DATABASE_HOST=127.0.0.1
67+
vendor/bin/phpunit tests/Integration/
68+
- name: Running the system tests
69+
run: vendor/bin/phpunit tests/System/;
70+
- name: Running static analysis
71+
run: vendor/bin/phpstan analyse -l 5 bin/ src/ tests/ public/;
72+
- name: Running PHPMD
73+
run: vendor/bin/phpmd src/ text config/PHPMD/rules.xml;
74+
- name: Running PHP_CodeSniffer
75+
run: vendor/bin/phpcs --standard=config/PhpCodeSniffer/ bin/ src/ tests/ public/;

src/TestingSupport/Traits/DatabaseTestTrait.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace PhpList\Core\TestingSupport\Traits;
@@ -121,8 +122,11 @@ protected function getConnection(): Connection
121122
{
122123
if ($this->databaseConnection === null) {
123124
if (self::$pdo === null) {
125+
$databaseHost = getenv('PHPLIST_DATABASE_HOST') ?: 'localhost';
126+
$databasePort = getenv('PHPLIST_DATABASE_PORT') ?: '3306';
127+
$databaseName = getenv('PHPLIST_DATABASE_NAME');
124128
self::$pdo = new \PDO(
125-
'mysql:dbname=' . getenv('PHPLIST_DATABASE_NAME'),
129+
'mysql:host='.$databaseHost.';port='.$databasePort.';dbname='.$databaseName,
126130
getenv('PHPLIST_DATABASE_USER'),
127131
getenv('PHPLIST_DATABASE_PASSWORD')
128132
);

0 commit comments

Comments
 (0)