From eb674509b41a8734f128520061f161ff574f42a5 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 21 Jan 2020 14:13:15 +0100 Subject: [PATCH 1/6] BaseTestCase: Read db host and port from env vars if available --- library/Icinga/Test/BaseTestCase.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Test/BaseTestCase.php b/library/Icinga/Test/BaseTestCase.php index fa7db57bd..286ec3059 100644 --- a/library/Icinga/Test/BaseTestCase.php +++ b/library/Icinga/Test/BaseTestCase.php @@ -210,7 +210,19 @@ namespace Icinga\Test { protected function createDbConfigFor($name) { if (array_key_exists($name, self::$dbConfiguration)) { - return new ConfigObject(self::$dbConfiguration[$name]); + $config = new ConfigObject(self::$dbConfiguration[$name]); + + $host = getenv(sprintf('ICINGAWEB_TEST_%s_HOST', strtoupper($name))); + if ($host) { + $config['host'] = $host; + } + + $port = getenv(sprintf('ICINGAWEB_TEST_%s_PORT', strtoupper($name))); + if ($port) { + $config['port'] = $port; + } + + return $config; } throw new RuntimeException('Configuration for database type not available: ' . $name); From 9e1d14666c3c48f70a03e5a600c415b736b91e13 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 21 Jan 2020 14:13:51 +0100 Subject: [PATCH 2/6] test: Load composer autoloader if available --- test/php/bootstrap.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/php/bootstrap.php b/test/php/bootstrap.php index 38c092fee..75912674c 100644 --- a/test/php/bootstrap.php +++ b/test/php/bootstrap.php @@ -24,9 +24,15 @@ set_include_path(implode(PATH_SEPARATOR, [ get_include_path() ])); -require_once 'Mockery/Loader.php'; -$mockeryLoader = new \Mockery\Loader; -$mockeryLoader->register(); +$vendorAutoload = $basePath . '/vendor/autoload.php'; +if (file_exists($vendorAutoload)) { + require_once $vendorAutoload; +} else { + require_once 'Mockery/Loader.php'; + + $mockeryLoader = new \Mockery\Loader; + $mockeryLoader->register(); +} require_once($icingaLibPath . '/Test/ClassLoader.php'); From dbedde7d7fd8e2c2688524fef78d191064aa4c83 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 21 Jan 2020 14:15:40 +0100 Subject: [PATCH 3/6] Add php action workflow --- .github/workflows/php.yml | 113 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 .github/workflows/php.yml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 000000000..cb2b37041 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,113 @@ +name: PHP Tests + +on: + push: + branches: + - master + - release/* + pull_request: + branches: + - master + +jobs: + lint: + name: Static analysis for php ${{ matrix.php }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] + os: ['ubuntu-latest'] + include: + - php: '5.6' + allow_failure: true + - php: '7.0' + allow_failure: true + + steps: + - name: Checkout code base + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v1 + with: + php-version: ${{ matrix.php }} + tools: phpcs + + - name: Setup dependencies + run: composer require -n --no-progress overtrue/phplint + + - name: PHP Lint + if: success() || matrix.allow_failure + run: ./vendor/bin/phplint -n --exclude={^vendor/.*} --exclude=library/Icinga/Util/String.php -- . + + - name: PHP CodeSniffer + if: success() || matrix.allow_failure + run: phpcs + + test: + name: Unit tests with php ${{ matrix.php }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + + env: + phpunit-version: 5.7.27 + mockery-version: 0.9.9 # *Any* other version is not compatible with PHP 5.6 and anything above phpunit 6 + + strategy: + fail-fast: false + matrix: + php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] + os: ['ubuntu-latest'] + + services: + mysql: + image: mariadb + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: icinga_unittest + MYSQL_USER: icinga_unittest + MYSQL_PASSWORD: icinga_unittest + options: >- + --health-cmd "mysql -s -uroot -proot -e'SHOW DATABASES;' 2> /dev/null | grep icinga_unittest > test" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 3306/tcp + + pgsql: + image: postgres + env: + POSTGRES_USER: icinga_unittest + POSTGRES_PASSWORD: icinga_unittest + POSTGRES_DB: icinga_unittest + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432/tcp + + steps: + - name: Checkout code base + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v1 + with: + php-version: ${{ matrix.php }} + tools: phpunit:${{ env.phpunit-version }} + extensions: mysql, pgsql, ldap + + - name: Setup dependencies + run: | + sudo locale-gen en_US.UTF-8 de_DE.UTF-8 fr_FR.UTF-8 + composer require -n --no-progress mockery/mockery:${{ env.mockery-version }} + + - name: PHPUnit + env: + ICINGAWEB_TEST_MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }} + ICINGAWEB_TEST_PGSQL_PORT: ${{ job.services.pgsql.ports['5432'] }} + run: phpunit -c modules/test/phpunit.xml --verbose From 776761bd6a506759cfcf8f9d11467ac7aa115582 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 21 Jan 2020 14:19:31 +0100 Subject: [PATCH 4/6] README.md: Replace travis badge with the one from github --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d45261009..03789565b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Icinga Web 2 -[![Build Status](https://travis-ci.org/Icinga/icingaweb2.png?branch=master)](https://travis-ci.org/Icinga/icingaweb2) +![Build Status](https://github.com/icinga/icingaweb2/workflows/PHP%20Tests/badge.svg?branch=master) [![Github Tag](https://img.shields.io/github/tag/Icinga/icingaweb2.svg)](https://github.com/Icinga/icingaweb2) ![Icinga Logo](https://icinga.com/wp-content/uploads/2014/06/icinga_logo.png) From 4b3240a22ebe3b661fcb7f049a304ed94daad483 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 21 Jan 2020 14:28:08 +0100 Subject: [PATCH 5/6] Remove travis integration --- .travis.yml | 71 ----------------------------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 93bb00a44..000000000 --- a/.travis.yml +++ /dev/null @@ -1,71 +0,0 @@ -language: php -dist: xenial -sudo: false - -php: - - '5.6' - - '7.1' - - '7.2' - - '7.3' - - '7.4' - - nightly - -env: - - CHECK=phpunit - -matrix: - include: - - env: CHECK=phpcs - php: '7.4' - - env: CHECK=phpcs - php: '7.3' - - env: CHECK=phpcs - php: '7.2' - - env: CHECK=phpcs - php: '7.1' - - env: CHECK=phpcs - php: '5.6' - - env: CHECK=syntax - php: 'nightly' - - env: CHECK=syntax - php: '7.4' - - env: CHECK=syntax - php: '7.3' - - env: CHECK=syntax - php: '7.2' - - env: CHECK=syntax - php: '7.1' - - env: CHECK=syntax - php: '5.6' - allow_failures: - - php: nightly - -services: - - mysql - - postgresql - -cache: - directories: - - vendor - -branches: - only: - - master - - /^v\d/ - -notifications: - email: false - -# also see: test/setup_vendor.sh -before_script: - - php -m - - '[ -z $LOCALE_GEN ] || sudo locale-gen en_US.UTF-8 de_DE.UTF-8 fr_FR.UTF-8' - - '[ -z $ENABLE_LDAP ] || phpenv config-add test/travis-ldap.ini' - - test/setup_vendor.sh - - 'if [ "$CHECK" = phpunit ]; then test/travis_database.sh; fi' - -script: - # also see: modules/test/application/clicommands/PhpCommand.php - - 'if [ "$CHECK" = phpcs ]; then php vendor/phpcs.phar; fi' - - 'if [ "$CHECK" = phpunit ]; then php vendor/phpunit.phar -c modules/test/phpunit.xml --verbose; fi' - - 'if [ "$CHECK" = syntax ]; then php test/check-syntax.php -e "^(\./)?vendor/" -e Icinga/Util/String.php; fi' From 4e2c1576da572b316270db3ee9114d1beba82150 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 22 Jan 2020 13:09:43 +0100 Subject: [PATCH 6/6] README.md: Add php version badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 03789565b..e19e4267f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Icinga Web 2 +[![PHP Support](https://img.shields.io/badge/php-%3E%3D%205.6-777BB4?logo=PHP)](https://php.net/) ![Build Status](https://github.com/icinga/icingaweb2/workflows/PHP%20Tests/badge.svg?branch=master) [![Github Tag](https://img.shields.io/github/tag/Icinga/icingaweb2.svg)](https://github.com/Icinga/icingaweb2)