diff --git a/.github/workflows/test-phpunit.yml b/.github/workflows/test-phpunit.yml new file mode 100644 index 000000000000..9f1a4b3744bb --- /dev/null +++ b/.github/workflows/test-phpunit.yml @@ -0,0 +1,104 @@ +name: PHPUnit + +on: + pull_request: + branches: + - develop + - '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 + 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 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 551f48120074..000000000000 --- a/.travis.yml +++ /dev/null @@ -1,60 +0,0 @@ -language: php - -php: - - 7.2 - - 7.3 - - 7.4 - - nightly - -matrix: - fast_finish: true - allow_failures: - - php: nightly - -global: - - CI=true - - CI_ENVIRONMENT=testing - -# Recommended by Travis support -sudo: required -dist: xenial -group: edge - -env: - - DB=mysqli - - DB=postgres - - DB=sqlite - -services: - - memcached - - mysql - - postgresql - - redis-server - -cache: - directories: - - vendor - -script: - - php vendor/bin/phpunit -v - -before_install: - - mysql -e "CREATE DATABASE IF NOT EXISTS test;" -uroot; - - mysql -e "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'test';" -uroot - - psql -c 'CREATE DATABASE test;' -U postgres - - sudo apt-get install ghostscript - - yes | pecl install imagick - -before_script: - - echo 'extension = memcached.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - echo 'extension = redis.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - | - if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ]]; then - git clone -b stable https://github.com/jedisct1/libsodium.git - cd libsodium && sudo ./configure && sudo make check && sudo make install && cd .. - printf "\n" | pecl install -f libsodium - fi - - composer install --prefer-source - -after_success: - - travis_retry php tests/bin/php-coveralls.phar -v diff --git a/README.md b/README.md index 1a4575702398..41bc739b5203 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/app/Config/Database.php b/app/Config/Database.php index ba60dcafda47..a0b46c35f45a 100644 --- a/app/Config/Database.php +++ b/app/Config/Database.php @@ -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]; - } - } - } } } diff --git a/app/Views/errors/cli/error_exception.php b/app/Views/errors/cli/error_exception.php index 592dd6e24833..be2abc5879f3 100644 --- a/app/Views/errors/cli/error_exception.php +++ b/app/Views/errors/cli/error_exception.php @@ -62,7 +62,7 @@ default: return var_export($value, true); } - }, array_values($error['args']))); + }, array_values($error['args'] ?? []))); $function .= '(' . $args . ')'; diff --git a/tests/_support/Config/Registrar.php b/tests/_support/Config/Registrar.php new file mode 100644 index 000000000000..47c2fbfda769 --- /dev/null +++ b/tests/_support/Config/Registrar.php @@ -0,0 +1,98 @@ + [ + '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; + } + +} diff --git a/tests/bin/php-coveralls.phar b/tests/bin/php-coveralls.phar deleted file mode 100755 index 30523379b445..000000000000 Binary files a/tests/bin/php-coveralls.phar and /dev/null differ diff --git a/tests/travis/Database.php b/tests/travis/Database.php deleted file mode 100644 index 93a618013e0c..000000000000 --- a/tests/travis/Database.php +++ /dev/null @@ -1,62 +0,0 @@ - [ - 'DSN' => '', - 'hostname' => 'localhost', - 'username' => 'travis', - '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' => [], - ], - - 'postgres' => [ - 'DSN' => '', - 'hostname' => 'localhost', - 'username' => 'postgres', - 'password' => '', - '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' => [], - ], - - 'sqlite' => [ - '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' => [], - ], - -];