Skip to content

Commit

Permalink
Add GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed May 2, 2024
1 parent 3088af9 commit 8b49c5a
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 1 deletion.
97 changes: 97 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: CI

on:
push:
pull_request:

env:
PSALM_PHP_VERSION: "8.3"
COVERAGE_PHP_VERSION: "8.3"

jobs:
psalm:
name: Psalm
runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PSALM_PHP_VERSION }}

- name: Install composer dependencies
uses: ramsey/composer-install@v3

- name: Run Psalm
run: vendor/bin/psalm --show-info=false --find-unused-psalm-suppress --no-progress

phpunit:
name: PHPUnit
runs-on: ubuntu-22.04

strategy:
fail-fast: false
matrix:
php-version:
- "8.1"
- "8.2"
- "8.3"
deps:
- "highest"
include:
- php-version: "8.1"
deps: "lowest"

services:
mysql:
image: "mysql:8.0"
ports:
- "3306:3306"
options: >-
--health-cmd "mysqladmin ping --silent"
env:
MYSQL_ROOT_PASSWORD: password

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: pcov

- name: Install composer dependencies
uses: ramsey/composer-install@v3
with:
dependency-versions: ${{ matrix.deps }}

- name: Run PHPUnit
run: vendor/bin/phpunit --fail-on-skipped
if: ${{ matrix.php-version != env.COVERAGE_PHP_VERSION }}
env:
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_USERNAME: root
DB_PASSWORD: password

- name: Run PHPUnit with coverage
run: |
mkdir -p build/logs
vendor/bin/phpunit --fail-on-skipped --coverage-clover build/logs/clover.xml
if: ${{ matrix.php-version == env.COVERAGE_PHP_VERSION }}
env:
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_USERNAME: root
DB_PASSWORD: password

- name: Upload coverage report to Coveralls
run: vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ matrix.php-version == env.COVERAGE_PHP_VERSION }}
18 changes: 17 additions & 1 deletion tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,25 @@ public static function setUpBeforeClass() : void
{
self::$logger = new DebugLogger();

$pdo = new \PDO('mysql:host=localhost;dbname=test', 'root', '');
$dbHost = getenv('DB_HOST');
$dbPort = getenv('DB_PORT');
$dbUsername = getenv('DB_USERNAME');
$dbPassword = getenv('DB_PASSWORD');

self::assertNotFalse($dbHost, 'Environment variable DB_HOST is not set');
self::assertNotFalse($dbPort, 'Environment variable DB_PORT is not set');
self::assertNotFalse($dbUsername, 'Environment variable DB_USERNAME is not set');
self::assertNotFalse($dbPassword, 'Environment variable DB_PASSWORD is not set');

$dsn = sprintf('mysql:host=%s;port=%s', $dbHost, $dbPort);
$pdo = new \PDO($dsn, $dbUsername, $dbPassword);
$driverConnection = new PDOConnection($pdo);
$connection = new Connection($driverConnection, self::$logger);

$connection->exec('DROP DATABASE IF EXISTS orm_tests');
$connection->exec('CREATE DATABASE orm_tests');
$connection->exec('USE orm_tests');

$classMetadata = require __DIR__ . '/Generated/ClassMetadata.php';

self::$connection = $connection;
Expand Down

0 comments on commit 8b49c5a

Please sign in to comment.