Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test framework with github actions #3689

Merged
merged 15 commits into from
Oct 2, 2020
104 changes: 104 additions & 0 deletions .github/workflows/test-phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: PHPUnit

on:
pull_request:
branches:
- develop
michalsn marked this conversation as resolved.
Show resolved Hide resolved
- '4.*'

jobs:

tests:
runs-on: ubuntu-latest

if: "!contains(github.event.head_commit.message, '[ci skip]')"

name: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}

strategy:
fail-fast: false
matrix:
php-versions: ['7.2', '7.3', '7.4']
db-platforms: ['MySQLi', 'Postgre', 'SQLite3']

services:
mysql:
image: mysql:5.7
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
redis:
image: redis
ports:
- 6379:6379
options: --health-cmd "redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3

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

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: composer:v2
extensions: imagick
coverage: xdebug
env:
update: true

- name: Install Memcached
uses: niden/actions-memcached@v7

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-progress --no-suggest --no-interaction --prefer-dist --optimize-autoloader
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}

- name: Test with PHPUnit
run: script -e -c "vendor/bin/phpunit -v"
env:
DB: ${{ matrix.db-platforms }}
TERM: xterm-256color

- name: Run Coveralls
run: |
composer global require twinh/php-coveralls
michalsn marked this conversation as resolved.
Show resolved Hide resolved
php-coveralls --coverage_clover=build/logs/clover.xml -v
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }}

coveralls-finish:
needs: [tests]
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
60 changes: 0 additions & 60 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CodeIgniter 4 Development

[![Build Status](https://travis-ci.org/codeigniter4/CodeIgniter4.svg?branch=develop)](https://travis-ci.org/codeigniter4/CodeIgniter4)
[![Build Status](https://github.com/codeigniter4/CodeIgniter4/workflows/PHPUnit/badge.svg?branch=develop)](https://github.com/codeigniter4/CodeIgniter4/actions?query=workflow%3A%22PHPUnit%22)
[![Coverage Status](https://coveralls.io/repos/github/codeigniter4/CodeIgniter4/badge.svg?branch=develop)](https://coveralls.io/github/codeigniter4/CodeIgniter4?branch=develop)
[![Downloads](https://poser.pugx.org/codeigniter4/framework/downloads)](https://packagist.org/packages/codeigniter4/framework)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/codeigniter4/CodeIgniter4)](https://packagist.org/packages/codeigniter4/framework)
Expand Down
15 changes: 0 additions & 15 deletions app/Config/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,6 @@ public function __construct()
if (ENVIRONMENT === 'testing')
{
$this->defaultGroup = 'tests';

// Under Travis-CI, we can set an ENV var named 'DB_GROUP'
// so that we can test against multiple databases.
if ($group = getenv('DB'))
{
if (is_file(TESTPATH . 'travis/Database.php'))
{
require TESTPATH . 'travis/Database.php';

if (! empty($dbconfig) && array_key_exists($group, $dbconfig))
{
$this->tests = $dbconfig[$group];
}
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/Views/errors/cli/error_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
default:
return var_export($value, true);
}
}, array_values($error['args'])));
}, array_values($error['args'] ?? [])));

$function .= '(' . $args . ')';

Expand Down
98 changes: 98 additions & 0 deletions tests/_support/Config/Registrar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php 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
*/
protected static $dbConfig = [
'MySQLi' => [
'DSN' => '',
'hostname' => '127.0.0.1',
'username' => 'root',
'password' => '',
'database' => 'test',
'DBDriver' => 'MySQLi',
'DBPrefix' => 'db_',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'charset' => 'utf8',
'DBCollat' => 'utf8_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' => (ENVIRONMENT !== 'production'),
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'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' => (ENVIRONMENT !== 'production'),
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 3306,
],
];

/**
* Override database config
*
* @return array
*/
public static function Database()
{
$config = [];

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

return $config;
}

}
Binary file removed tests/bin/php-coveralls.phar
Binary file not shown.
62 changes: 0 additions & 62 deletions tests/travis/Database.php

This file was deleted.