Skip to content

Commit

Permalink
add tests for every database handler
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsn committed Sep 19, 2024
1 parent 0bc2957 commit ec1465a
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 9 deletions.
90 changes: 82 additions & 8 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,68 @@ on:

jobs:
main:
name: PHP ${{ matrix.php-versions }} Unit Tests
runs-on: ubuntu-22.04
name: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
strategy:
matrix:
php-versions: ['8.1', '8.2', '8.3']
db-platforms: ['MySQLi', 'SQLite3']
include:
# Postgre
- php-versions: '8.1'
db-platforms: Postgre
# SQLSRV
- php-versions: '8.1'
db-platforms: SQLSRV
# OCI8
- php-versions: '8.1'
db-platforms: OCI8

services:
mysql:
image: mysql:8.0
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: test
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test
ports:
- 5432:5432
options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3

mssql:
image: mcr.microsoft.com/mssql/server:2019-CU10-ubuntu-20.04
env:
SA_PASSWORD: 1Secure*Password1
ACCEPT_EULA: Y
MSSQL_PID: Developer
ports:
- 1433:1433
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

oracle:
image: gvenzl/oracle-xe:18
env:
ORACLE_RANDOM_PASSWORD: true
APP_USER: ORACLE
APP_USER_PASSWORD: ORACLE
ports:
- 1521:1521
options: >-
--health-cmd healthcheck.sh
--health-interval 20s
--health-timeout 10s
--health-retries 10
redis:
image: redis
ports:
Expand All @@ -34,12 +92,27 @@ jobs:
--health-timeout=5s
--health-retries=3
if: "!contains(github.event.head_commit.message, '[ci skip]')"
strategy:
matrix:
php-versions: ['8.1', '8.2', '8.3']

steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: false

# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: false
docker-images: true
swap-storage: true

- name: Create database for MSSQL Server
if: matrix.db-platforms == 'SQLSRV'
run: sqlcmd -S 127.0.0.1 -U sa -P 1Secure*Password1 -Q "CREATE DATABASE test"

- name: Checkout
uses: actions/checkout@v4

Expand Down Expand Up @@ -74,6 +147,7 @@ jobs:
- name: Test with PHPUnit
run: vendor/bin/phpunit --coverage-text
env:
DB: ${{ matrix.db-platforms }}
TERM: xterm-256color
TACHYCARDIA_MONITOR_GA: enabled

Expand All @@ -86,7 +160,7 @@ jobs:
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }}
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}

coveralls:
needs: [main]
Expand Down
2 changes: 1 addition & 1 deletion src/Models/QueueJobModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private function setPriority(BaseBuilder $builder, array $priority): BaseBuilder
$builder->whereIn('priority', $priority);

if ($priority !== ['default']) {
if ($this->db->DBDriver === 'SQLite3') {
if ($this->db->DBDriver !== 'MySQLi') {
$builder->orderBy(
'CASE priority '
. implode(
Expand Down
143 changes: 143 additions & 0 deletions tests/_support/Config/Registrar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php

declare(strict_types=1);

/**
* This file is part of CodeIgniter Queue.
*
* (c) CodeIgniter Foundation <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace Tests\Support\Config;

/**
* Class Registrar
*
* Provides a basic registrar class for testing BaseConfig registration functions.
*/
class Registrar
{
/**
* DB config array for testing purposes.
*
* @var array<string, array<string, array<string, bool|int|string>|bool|int|string>>
*/
protected static array $dbConfig = [
'MySQLi' => [
'DSN' => '',
'hostname' => '127.0.0.1',
'username' => 'root',
'password' => '',
'database' => 'test',
'DBDriver' => 'MySQLi',
'DBPrefix' => 'db_',
'pConnect' => false,
'DBDebug' => true,
'charset' => 'utf8mb4',
'DBCollat' => 'utf8mb4_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 3306,
],
'Postgre' => [
'DSN' => '',
'hostname' => 'localhost',
'username' => 'postgres',
'password' => 'postgres',
'database' => 'test',
'DBDriver' => 'Postgre',
'DBPrefix' => 'db_',
'pConnect' => false,
'DBDebug' => true,
'charset' => 'utf8',
'DBCollat' => '',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 5432,
],
'SQLite3' => [
'DSN' => '',
'hostname' => 'localhost',
'username' => '',
'password' => '',
'database' => 'database.db',
'DBDriver' => 'SQLite3',
'DBPrefix' => 'db_',
'pConnect' => false,
'DBDebug' => true,
'charset' => 'utf8',
'DBCollat' => '',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 3306,
'foreignKeys' => true,
],
'SQLSRV' => [
'DSN' => '',
'hostname' => 'localhost',
'username' => 'sa',
'password' => '1Secure*Password1',
'database' => 'test',
'DBDriver' => 'SQLSRV',
'DBPrefix' => 'db_',
'pConnect' => false,
'DBDebug' => true,
'charset' => 'utf8',
'DBCollat' => '',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 1433,
],
'OCI8' => [
'DSN' => 'localhost:1521/XEPDB1',
'hostname' => '',
'username' => 'ORACLE',
'password' => 'ORACLE',
'database' => '',
'DBDriver' => 'OCI8',
'DBPrefix' => 'db_',
'pConnect' => false,
'DBDebug' => true,
'charset' => 'AL32UTF8',
'DBCollat' => '',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
],
];

/**
* Override database config
*
* @return array<string, array<string, bool|int|string>|bool|int|string>
*/
public static function Database(): array
{
$config = [];

// Under GitHub Actions, we can set an ENV var named 'DB'
// so that we can test against multiple databases.
if (($group = getenv('DB')) && isset(self::$dbConfig[$group])) {
$config['tests'] = self::$dbConfig[$group];
}

return $config;
}
}

0 comments on commit ec1465a

Please sign in to comment.