Skip to content

Commit 237e731

Browse files
committed
chore: add multiple db platforms in GA workflow PHPUnit
1 parent fa994dc commit 237e731

File tree

2 files changed

+215
-3
lines changed

2 files changed

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

0 commit comments

Comments
 (0)