Skip to content

Commit 43a7f0a

Browse files
authored
Merge pull request #331 from codeigniter4/github-action-phpunit-multi-db
chore: add multiple db platforms in GA workflow PHPUnit
2 parents 1ef3977 + b5a7322 commit 43a7f0a

File tree

2 files changed

+217
-3
lines changed

2 files changed

+217
-3
lines changed

.github/workflows/phpunit.yml

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,84 @@ on:
2020

2121
jobs:
2222
main:
23-
name: PHP ${{ matrix.php-versions }} Unit Tests
23+
name: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
2424
runs-on: ubuntu-latest
2525
if: "!contains(github.event.head_commit.message, '[ci skip]')"
2626
strategy:
2727
matrix:
2828
php-versions: ['7.4', '8.0', '8.1']
29+
db-platforms: ['MySQLi', 'Postgre', 'SQLite3', 'SQLSRV', 'OCI8']
30+
mysql-versions: [ '5.7' ]
31+
include:
32+
- php-versions: '7.4'
33+
db-platforms: MySQLi
34+
mysql-versions: '8.0'
35+
36+
services:
37+
mysql:
38+
image: mysql:${{ matrix.mysql-versions }}
39+
env:
40+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
41+
MYSQL_DATABASE: test
42+
ports:
43+
- 3306:3306
44+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
45+
46+
postgres:
47+
image: postgres
48+
env:
49+
POSTGRES_USER: postgres
50+
POSTGRES_PASSWORD: postgres
51+
POSTGRES_DB: test
52+
ports:
53+
- 5432:5432
54+
options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3
55+
56+
mssql:
57+
image: mcr.microsoft.com/mssql/server:2019-CU10-ubuntu-20.04
58+
env:
59+
SA_PASSWORD: 1Secure*Password1
60+
ACCEPT_EULA: Y
61+
MSSQL_PID: Developer
62+
ports:
63+
- 1433:1433
64+
options: --health-cmd="/opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U sa -P 1Secure*Password1 -Q 'SELECT @@VERSION'" --health-interval=10s --health-timeout=5s --health-retries=3
65+
66+
oracle:
67+
image: quillbuilduser/oracle-18-xe
68+
env:
69+
ORACLE_ALLOW_REMOTE: true
70+
ports:
71+
- 1521:1521
72+
options: --health-cmd="/opt/oracle/product/18c/dbhomeXE/bin/sqlplus -s sys/Oracle18@oracledbxe/XE as sysdba <<< 'SELECT 1 FROM DUAL'" --health-interval=10s --health-timeout=5s --health-retries=3
2973

3074
steps:
75+
- name: Create database for MSSQL Server
76+
if: matrix.db-platforms == 'SQLSRV'
77+
run: sqlcmd -S 127.0.0.1 -U sa -P 1Secure*Password1 -Q "CREATE DATABASE test"
78+
79+
- name: Install Oracle InstantClient
80+
if: matrix.db-platforms == 'OCI8'
81+
run: |
82+
sudo apt-get install wget libaio1 alien
83+
sudo wget https://download.oracle.com/otn_software/linux/instantclient/185000/oracle-instantclient18.5-basic-18.5.0.0.0-3.x86_64.rpm
84+
sudo wget https://download.oracle.com/otn_software/linux/instantclient/185000/oracle-instantclient18.5-devel-18.5.0.0.0-3.x86_64.rpm
85+
sudo wget https://download.oracle.com/otn_software/linux/instantclient/185000/oracle-instantclient18.5-sqlplus-18.5.0.0.0-3.x86_64.rpm
86+
sudo alien oracle-instantclient18.5-basic-18.5.0.0.0-3.x86_64.rpm
87+
sudo alien oracle-instantclient18.5-devel-18.5.0.0.0-3.x86_64.rpm
88+
sudo alien oracle-instantclient18.5-sqlplus-18.5.0.0.0-3.x86_64.rpm
89+
sudo dpkg -i oracle-instantclient18.5-basic_18.5.0.0.0-4_amd64.deb oracle-instantclient18.5-devel_18.5.0.0.0-4_amd64.deb oracle-instantclient18.5-sqlplus_18.5.0.0.0-4_amd64.deb
90+
echo "LD_LIBRARY_PATH=/lib/oracle/18.5/client64/lib/" >> $GITHUB_ENV
91+
echo "NLS_LANG=AMERICAN_AMERICA.UTF8" >> $GITHUB_ENV
92+
echo "C_INCLUDE_PATH=/usr/include/oracle/18.5/client64" >> $GITHUB_ENV
93+
echo 'NLS_DATE_FORMAT=YYYY-MM-DD HH24:MI:SS' >> $GITHUB_ENV
94+
echo 'NLS_TIMESTAMP_FORMAT=YYYY-MM-DD HH24:MI:SS' >> $GITHUB_ENV
95+
echo 'NLS_TIMESTAMP_TZ_FORMAT=YYYY-MM-DD HH24:MI:SS' >> $GITHUB_ENV
96+
97+
- name: Create database for Oracle Database
98+
if: matrix.db-platforms == 'OCI8'
99+
run: echo -e "ALTER SESSION SET CONTAINER = XEPDB1;\nCREATE BIGFILE TABLESPACE \"TEST\" DATAFILE '/opt/oracle/product/18c/dbhomeXE/dbs/TEST' SIZE 10M AUTOEXTEND ON MAXSIZE UNLIMITED SEGMENT SPACE MANAGEMENT AUTO EXTENT MANAGEMENT LOCAL AUTOALLOCATE;\nCREATE USER \"ORACLE\" IDENTIFIED BY \"ORACLE\" DEFAULT TABLESPACE \"TEST\" TEMPORARY TABLESPACE TEMP QUOTA UNLIMITED ON \"TEST\";\nGRANT CONNECT,RESOURCE TO \"ORACLE\";\nexit;" | /lib/oracle/18.5/client64/bin/sqlplus -s sys/Oracle18@localhost:1521/XE as sysdba
100+
31101
- name: Checkout
32102
uses: actions/checkout@v3
33103

@@ -36,7 +106,7 @@ jobs:
36106
with:
37107
php-version: ${{ matrix.php-versions }}
38108
tools: composer, phive, phpunit
39-
extensions: intl, json, mbstring, gd, xdebug, xml, sqlite3
109+
extensions: intl, json, mbstring, gd, xdebug, xml, sqlite3, sqlsrv, oci8, pgsql
40110
coverage: xdebug
41111
env:
42112
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -63,6 +133,7 @@ jobs:
63133
- name: Test with PHPUnit
64134
run: vendor/bin/phpunit --verbose --coverage-text --testsuite main
65135
env:
136+
DB: ${{ matrix.db-platforms }}
66137
TERM: xterm-256color
67138
TACHYCARDIA_MONITOR_GA: enabled
68139

@@ -75,7 +146,7 @@ jobs:
75146
env:
76147
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77148
COVERALLS_PARALLEL: true
78-
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }}
149+
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
79150

80151
coveralls:
81152
needs: [main]
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of CodeIgniter 4 framework.
7+
*
8+
* (c) CodeIgniter Foundation <[email protected]>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*/
13+
14+
namespace Tests\Support\Config;
15+
16+
/**
17+
* Class Registrar
18+
*
19+
* Provides a basic registrar class for testing BaseConfig registration functions.
20+
*/
21+
class Registrar
22+
{
23+
/**
24+
* DB config array for testing purposes.
25+
*
26+
* @var array
27+
*/
28+
protected static $dbConfig = [
29+
'MySQLi' => [
30+
'DSN' => '',
31+
'hostname' => '127.0.0.1',
32+
'username' => 'root',
33+
'password' => '',
34+
'database' => 'test',
35+
'DBDriver' => 'MySQLi',
36+
'DBPrefix' => 'db_',
37+
'pConnect' => false,
38+
'DBDebug' => (ENVIRONMENT !== 'production'),
39+
'charset' => 'utf8',
40+
'DBCollat' => 'utf8_general_ci',
41+
'swapPre' => '',
42+
'encrypt' => false,
43+
'compress' => false,
44+
'strictOn' => false,
45+
'failover' => [],
46+
'port' => 3306,
47+
],
48+
'Postgre' => [
49+
'DSN' => '',
50+
'hostname' => 'localhost',
51+
'username' => 'postgres',
52+
'password' => 'postgres',
53+
'database' => 'test',
54+
'DBDriver' => 'Postgre',
55+
'DBPrefix' => 'db_',
56+
'pConnect' => false,
57+
'DBDebug' => (ENVIRONMENT !== 'production'),
58+
'charset' => 'utf8',
59+
'DBCollat' => 'utf8_general_ci',
60+
'swapPre' => '',
61+
'encrypt' => false,
62+
'compress' => false,
63+
'strictOn' => false,
64+
'failover' => [],
65+
'port' => 5432,
66+
],
67+
'SQLite3' => [
68+
'DSN' => '',
69+
'hostname' => 'localhost',
70+
'username' => '',
71+
'password' => '',
72+
'database' => 'database.db',
73+
'DBDriver' => 'SQLite3',
74+
'DBPrefix' => 'db_',
75+
'pConnect' => false,
76+
'DBDebug' => (ENVIRONMENT !== 'production'),
77+
'charset' => 'utf8',
78+
'DBCollat' => 'utf8_general_ci',
79+
'swapPre' => '',
80+
'encrypt' => false,
81+
'compress' => false,
82+
'strictOn' => false,
83+
'failover' => [],
84+
'port' => 3306,
85+
'foreignKeys' => true,
86+
],
87+
'SQLSRV' => [
88+
'DSN' => '',
89+
'hostname' => 'localhost',
90+
'username' => 'sa',
91+
'password' => '1Secure*Password1',
92+
'database' => 'test',
93+
'DBDriver' => 'SQLSRV',
94+
'DBPrefix' => 'db_',
95+
'pConnect' => false,
96+
'DBDebug' => (ENVIRONMENT !== 'production'),
97+
'charset' => 'utf8',
98+
'DBCollat' => 'utf8_general_ci',
99+
'swapPre' => '',
100+
'encrypt' => false,
101+
'compress' => false,
102+
'strictOn' => false,
103+
'failover' => [],
104+
'port' => 1433,
105+
],
106+
'OCI8' => [
107+
'DSN' => 'localhost:1521/XEPDB1',
108+
'hostname' => '',
109+
'username' => 'ORACLE',
110+
'password' => 'ORACLE',
111+
'database' => '',
112+
'DBDriver' => 'OCI8',
113+
'DBPrefix' => 'db_',
114+
'pConnect' => false,
115+
'DBDebug' => (ENVIRONMENT !== 'production'),
116+
'charset' => 'utf8',
117+
'DBCollat' => 'utf8_general_ci',
118+
'swapPre' => '',
119+
'encrypt' => false,
120+
'compress' => false,
121+
'strictOn' => false,
122+
'failover' => [],
123+
],
124+
];
125+
126+
/**
127+
* Override database config
128+
*
129+
* @return array
130+
*/
131+
public static function Database()
132+
{
133+
$config = [];
134+
135+
// Under GitHub Actions, we can set an ENV var named 'DB'
136+
// so that we can test against multiple databases.
137+
if (($group = getenv('DB')) && ! empty(self::$dbConfig[$group])) {
138+
$config['tests'] = self::$dbConfig[$group];
139+
}
140+
141+
return $config;
142+
}
143+
}

0 commit comments

Comments
 (0)