172 lines
5.1 KiB
YAML
172 lines
5.1 KiB
YAML
name: Tests
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- develop
|
|
pull_request:
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
phpunit:
|
|
name: PHPUnit
|
|
runs-on: ubuntu-latest
|
|
|
|
services:
|
|
mysql:
|
|
image: mariadb:10.11
|
|
env:
|
|
MYSQL_ROOT_PASSWORD: root
|
|
MYSQL_DATABASE: alrahma_test
|
|
MYSQL_USER: alrahma
|
|
MYSQL_PASSWORD: alrahma
|
|
ports:
|
|
- 3306:3306
|
|
options: >-
|
|
--health-cmd="mariadb-admin ping -h 127.0.0.1 -uroot -proot"
|
|
--health-interval=10s
|
|
--health-timeout=5s
|
|
--health-retries=10
|
|
|
|
env:
|
|
GIT_SSL_NO_VERIFY: 'true'
|
|
CI_ENVIRONMENT: testing
|
|
TEST_DB_HOST: mysql
|
|
TEST_DB_PORT: 3306
|
|
TEST_DB_NAME: alrahma_test
|
|
TEST_DB_USER: alrahma
|
|
TEST_DB_PASSWORD: alrahma
|
|
database.tests.hostname: mysql
|
|
database.tests.database: alrahma_test
|
|
database.tests.username: alrahma
|
|
database.tests.password: alrahma
|
|
database.tests.DBDriver: MySQLi
|
|
database.tests.DBPrefix: ''
|
|
database.tests.port: 3306
|
|
JWT_SECRET: test-secret-for-ci
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup PHP
|
|
uses: shivammathur/setup-php@v2
|
|
with:
|
|
php-version: '8.2'
|
|
extensions: dom, gd, intl, mbstring, mysqli, zip
|
|
coverage: xdebug
|
|
|
|
- name: Validate Composer config
|
|
run: composer validate --no-check-publish --strict
|
|
|
|
- name: Install dependencies
|
|
run: composer install --no-interaction --prefer-dist --no-progress
|
|
|
|
- name: Prepare writable directories
|
|
run: |
|
|
mkdir -p \
|
|
writable/cache/testing \
|
|
writable/logs \
|
|
writable/session \
|
|
writable/uploads \
|
|
writable/debugbar
|
|
chown -R "$(id -u):$(id -g)" writable || true
|
|
chmod -R u+rwX,g+rwX writable
|
|
|
|
- name: Verify writable cache
|
|
run: |
|
|
test -d writable/cache/testing
|
|
test -w writable/cache/testing
|
|
touch writable/cache/testing/.ci-write-test
|
|
rm writable/cache/testing/.ci-write-test
|
|
|
|
- name: Verify database configuration
|
|
run: |
|
|
php -d variables_order=EGPCS -r '
|
|
define("FCPATH", __DIR__ . "/public/");
|
|
define("ENVIRONMENT", getenv("CI_ENVIRONMENT") ?: "production");
|
|
require "app/Config/Paths.php";
|
|
$paths = new Config\Paths();
|
|
require $paths->systemDirectory . "/Boot.php";
|
|
CodeIgniter\Boot::bootConsole($paths);
|
|
|
|
$database = config("Database");
|
|
$dbConfig = $database->{$database->defaultGroup};
|
|
|
|
echo "Environment: " . ENVIRONMENT . PHP_EOL;
|
|
echo "DB group: " . $database->defaultGroup . PHP_EOL;
|
|
echo "DB host: " . $dbConfig["hostname"] . PHP_EOL;
|
|
echo "DB port: " . $dbConfig["port"] . PHP_EOL;
|
|
echo "DB name: " . $dbConfig["database"] . PHP_EOL;
|
|
'
|
|
|
|
- name: Wait for MariaDB
|
|
run: |
|
|
for attempt in $(seq 1 30); do
|
|
php -r '
|
|
mysqli_report(MYSQLI_REPORT_OFF);
|
|
$db = @new mysqli(
|
|
getenv("TEST_DB_HOST"),
|
|
getenv("TEST_DB_USER"),
|
|
getenv("TEST_DB_PASSWORD"),
|
|
getenv("TEST_DB_NAME"),
|
|
(int) getenv("TEST_DB_PORT")
|
|
);
|
|
|
|
exit($db->connect_errno === 0 ? 0 : 1);
|
|
' && break
|
|
|
|
echo "Waiting for MariaDB, attempt ${attempt}/30"
|
|
sleep 2
|
|
done
|
|
|
|
php -r '
|
|
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
|
|
|
new mysqli(
|
|
getenv("TEST_DB_HOST"),
|
|
getenv("TEST_DB_USER"),
|
|
getenv("TEST_DB_PASSWORD"),
|
|
getenv("TEST_DB_NAME"),
|
|
(int) getenv("TEST_DB_PORT")
|
|
);
|
|
|
|
echo "MariaDB connection successful\n";
|
|
'
|
|
|
|
- name: Import baseline schema
|
|
run: php tests/_support/import_baseline.php Database_Dump/u280815660_school_12072025
|
|
|
|
- name: Run database migrations
|
|
run: |
|
|
php -d variables_order=EGPCS spark migrate --all --no-interaction
|
|
php -r '
|
|
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
|
|
|
$db = new mysqli(
|
|
getenv("TEST_DB_HOST"),
|
|
getenv("TEST_DB_USER"),
|
|
getenv("TEST_DB_PASSWORD"),
|
|
getenv("TEST_DB_NAME"),
|
|
(int) getenv("TEST_DB_PORT")
|
|
);
|
|
|
|
$tables = [];
|
|
$result = $db->query("SHOW TABLES");
|
|
while ($row = $result->fetch_array(MYSQLI_NUM)) {
|
|
$tables[$row[0]] = true;
|
|
}
|
|
|
|
foreach (["users", "students", "attendance_data"] as $table) {
|
|
if (!isset($tables[$table])) {
|
|
fwrite(STDERR, "Migration schema missing required table: {$table}\n");
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
echo "Migration schema verified\n";
|
|
'
|
|
|
|
- name: Run tests
|
|
run: composer test
|