Skip to content

Commit ec1465a

Browse files
committed
add tests for every database handler
1 parent 0bc2957 commit ec1465a

File tree

3 files changed

+226
-9
lines changed

3 files changed

+226
-9
lines changed

.github/workflows/phpunit.yml

+82-8
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,68 @@ on:
2020

2121
jobs:
2222
main:
23-
name: PHP ${{ matrix.php-versions }} Unit Tests
24-
runs-on: ubuntu-22.04
23+
name: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
24+
runs-on: ubuntu-latest
25+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
26+
strategy:
27+
matrix:
28+
php-versions: ['8.1', '8.2', '8.3']
29+
db-platforms: ['MySQLi', 'SQLite3']
30+
include:
31+
# Postgre
32+
- php-versions: '8.1'
33+
db-platforms: Postgre
34+
# SQLSRV
35+
- php-versions: '8.1'
36+
db-platforms: SQLSRV
37+
# OCI8
38+
- php-versions: '8.1'
39+
db-platforms: OCI8
2540

2641
services:
42+
mysql:
43+
image: mysql:8.0
44+
env:
45+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
46+
MYSQL_DATABASE: test
47+
ports:
48+
- 3306:3306
49+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
50+
51+
postgres:
52+
image: postgres
53+
env:
54+
POSTGRES_USER: postgres
55+
POSTGRES_PASSWORD: postgres
56+
POSTGRES_DB: test
57+
ports:
58+
- 5432:5432
59+
options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3
60+
61+
mssql:
62+
image: mcr.microsoft.com/mssql/server:2019-CU10-ubuntu-20.04
63+
env:
64+
SA_PASSWORD: 1Secure*Password1
65+
ACCEPT_EULA: Y
66+
MSSQL_PID: Developer
67+
ports:
68+
- 1433:1433
69+
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
70+
71+
oracle:
72+
image: gvenzl/oracle-xe:18
73+
env:
74+
ORACLE_RANDOM_PASSWORD: true
75+
APP_USER: ORACLE
76+
APP_USER_PASSWORD: ORACLE
77+
ports:
78+
- 1521:1521
79+
options: >-
80+
--health-cmd healthcheck.sh
81+
--health-interval 20s
82+
--health-timeout 10s
83+
--health-retries 10
84+
2785
redis:
2886
image: redis
2987
ports:
@@ -34,12 +92,27 @@ jobs:
3492
--health-timeout=5s
3593
--health-retries=3
3694
37-
if: "!contains(github.event.head_commit.message, '[ci skip]')"
38-
strategy:
39-
matrix:
40-
php-versions: ['8.1', '8.2', '8.3']
41-
4295
steps:
96+
- name: Free Disk Space (Ubuntu)
97+
uses: jlumbroso/free-disk-space@main
98+
with:
99+
# this might remove tools that are actually needed,
100+
# if set to "true" but frees about 6 GB
101+
tool-cache: false
102+
103+
# all of these default to true, but feel free to set to
104+
# "false" if necessary for your workflow
105+
android: true
106+
dotnet: true
107+
haskell: true
108+
large-packages: false
109+
docker-images: true
110+
swap-storage: true
111+
112+
- name: Create database for MSSQL Server
113+
if: matrix.db-platforms == 'SQLSRV'
114+
run: sqlcmd -S 127.0.0.1 -U sa -P 1Secure*Password1 -Q "CREATE DATABASE test"
115+
43116
- name: Checkout
44117
uses: actions/checkout@v4
45118

@@ -74,6 +147,7 @@ jobs:
74147
- name: Test with PHPUnit
75148
run: vendor/bin/phpunit --coverage-text
76149
env:
150+
DB: ${{ matrix.db-platforms }}
77151
TERM: xterm-256color
78152
TACHYCARDIA_MONITOR_GA: enabled
79153

@@ -86,7 +160,7 @@ jobs:
86160
env:
87161
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88162
COVERALLS_PARALLEL: true
89-
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }}
163+
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
90164

91165
coveralls:
92166
needs: [main]

src/Models/QueueJobModel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private function setPriority(BaseBuilder $builder, array $priority): BaseBuilder
111111
$builder->whereIn('priority', $priority);
112112

113113
if ($priority !== ['default']) {
114-
if ($this->db->DBDriver === 'SQLite3') {
114+
if ($this->db->DBDriver !== 'MySQLi') {
115115
$builder->orderBy(
116116
'CASE priority '
117117
. implode(

tests/_support/Config/Registrar.php

+143
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 Queue.
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<string, array<string, array<string, bool|int|string>|bool|int|string>>
27+
*/
28+
protected static array $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' => true,
39+
'charset' => 'utf8mb4',
40+
'DBCollat' => 'utf8mb4_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' => true,
58+
'charset' => 'utf8',
59+
'DBCollat' => '',
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' => true,
77+
'charset' => 'utf8',
78+
'DBCollat' => '',
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' => true,
97+
'charset' => 'utf8',
98+
'DBCollat' => '',
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' => true,
116+
'charset' => 'AL32UTF8',
117+
'DBCollat' => '',
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<string, array<string, bool|int|string>|bool|int|string>
130+
*/
131+
public static function Database(): array
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')) && isset(self::$dbConfig[$group])) {
138+
$config['tests'] = self::$dbConfig[$group];
139+
}
140+
141+
return $config;
142+
}
143+
}

0 commit comments

Comments
 (0)