Skip to content

Commit

Permalink
Add php action workflow (#2309)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg authored Aug 31, 2023
2 parents fc7bfe7 + 48c4ae1 commit 079bf87
Show file tree
Hide file tree
Showing 27 changed files with 245 additions and 227 deletions.
173 changes: 173 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
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: ['7.2', '7.3', '7.4', '8.0', '8.1']
os: ['ubuntu-latest']

steps:
- name: Checkout code base
uses: actions/checkout@v3

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

- name: Setup dependencies
run: composer require -n --no-progress overtrue/phplint

- name: PHP Lint
if: ${{ ! cancelled() }}
run: ./vendor/bin/phplint -n --exclude={^vendor/.*} -- .

- name: PHP CodeSniffer
if: ${{ ! cancelled() }}
run: phpcs

test:
name: Unit tests with php ${{ matrix.php }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}

env:
phpunit-version: 9.5

strategy:
fail-fast: false
matrix:
php: ['7.2', '7.3', '7.4', '8.0', '8.1']
os: ['ubuntu-latest']
include:
- php: '7.2'
phpunit-version: 8.5

services:
mysql:
image: mariadb
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: director_test
MYSQL_USER: director_test
MYSQL_PASSWORD: director_test
options: >-
--health-cmd "mariadb -s -uroot -proot -e'SHOW DATABASES;' 2> /dev/null | grep director_test > test"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 3306/tcp

pgsql:
image: postgres
env:
POSTGRES_USER: director_test
POSTGRES_PASSWORD: director_test
POSTGRES_DB: director_test
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@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: phpunit:${{ matrix.phpunit-version || env.phpunit-version }}
extensions: mysql, pgsql

- name: Setup Icinga Web
run: |
git clone --depth 1 https://github.com/Icinga/icingaweb2.git _icingaweb2
ln -s `pwd` _icingaweb2/modules/director
- name: Setup Libraries
run: |
mkdir _libraries
git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-library.git _libraries/ipl
git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-thirdparty.git _libraries/vendor
- name: Setup Incubator
run: |
git clone --depth 1 https://github.com/Icinga/icingaweb2-module-incubator _icingaweb2/modules/incubator
mkdir -p test/config/enabledModules
cd _icingaweb2/modules/incubator
ln -s `pwd` ../../../test/config/enabledModules/incubator
composer require --no-update \
"gipfl/calendar": "dev-master as 99.x-dev" \
"gipfl/cli": "dev-master as 99.x-dev" \
"gipfl/curl": "dev-master as 99.x-dev" \
"gipfl/data-type": "dev-master as 99.x-dev" \
"gipfl/db-migration": "dev-master as 99.x-dev" \
"gipfl/diff": "dev-master as 99.x-dev" \
"gipfl/format": "dev-master as 99.x-dev" \
"gipfl/icinga-bundles": "dev-master as 99.x-dev" \
"gipfl/icinga-cli-daemon": "dev-master as 99.x-dev" \
"gipfl/icingaweb2": "dev-master as 99.x-dev" \
"gipfl/influxdb": "dev-master as 99.x-dev" \
"gipfl/json": "dev-master as 99.x-dev" \
"gipfl/linux-health": "dev-master as 99.x-dev" \
"gipfl/log": "dev-master as 99.x-dev" \
"gipfl/process": "dev-master as 99.x-dev" \
"gipfl/protocol-jsonrpc": "dev-master as 99.x-dev" \
"gipfl/protocol-netstring": "dev-master as 99.x-dev" \
"gipfl/react-utils": "dev-master as 99.x-dev" \
"gipfl/simple-daemon": "dev-master as 99.x-dev" \
"gipfl/socket": "dev-master as 99.x-dev" \
"gipfl/stream": "dev-master as 99.x-dev" \
"gipfl/systemd": "dev-master as 99.x-dev" \
"gipfl/translation": "dev-master as 99.x-dev" \
"gipfl/web": "dev-master as 99.x-dev" \
"gipfl/zfdb": "dev-master as 99.x-dev" \
"gipfl/zfdbstore": "dev-master as 99.x-dev"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
bin/make-release.sh snapshot
- name: PHPUnit with MySQL
if: ${{ ! cancelled() }}
env:
ICINGAWEB_LIBDIR: _libraries
ICINGAWEB_CONFIGDIR: test/config
DIRECTOR_TESTDB_RES: Director MySQL TestDB
DIRECTOR_TESTDB: director_test
DIRECTOR_TESTDB_HOST: 127.0.0.1
DIRECTOR_TESTDB_PORT: ${{ job.services.mysql.ports['3306'] }}
DIRECTOR_TESTDB_USER: director_test
DIRECTOR_TESTDB_PASSWORD: director_test
run: phpunit --verbose --bootstrap _icingaweb2/test/php/bootstrap.php

- name: PHPUnit with PostgreSQL
if: ${{ ! cancelled() }}
env:
ICINGAWEB_LIBDIR: _libraries
ICINGAWEB_CONFIGDIR: test/config
DIRECTOR_TESTDB_RES: Director PostgreSQL TestDB
DIRECTOR_TESTDB: director_test
DIRECTOR_TESTDB_HOST: 127.0.0.1
DIRECTOR_TESTDB_PORT: ${{ job.services.pgsql.ports['5432'] }}
DIRECTOR_TESTDB_USER: director_test
DIRECTOR_TESTDB_PASSWORD: director_test
run: phpunit --verbose --bootstrap _icingaweb2/test/php/bootstrap.php
42 changes: 0 additions & 42 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion application/forms/IcingaCloneObjectForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ protected function enumServiceSets()
return $db->fetchPairs(
$db->select()
->from('icinga_service_set', ['id', 'object_name'])
->where('object_type = ?','template')
->where('object_type = ?', 'template')
->order('object_name')
);
}
Expand Down
10 changes: 3 additions & 7 deletions doc/93-Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ there is probably already someone running them from time to time. So, just
lean back with full trust in our development toolchain and spend your time
elsewhere ;-) Cheers!

### Tests on Travis-CI
### Tests on GitHub

When pushing to [GitHub](https://github.com/Icinga/icingaweb2-module-director/)
or sending pull requests, Unit-Tests are automatically triggered on
[Travis-CI](https://travis-ci.org/Icinga/icingaweb2-module-director):
or sending pull requests, Unit-Tests are automatically triggered.

[![Build Status](https://travis-ci.org/Icinga/icingaweb2-module-director.svg?branch=master)](https://travis-ci.org/Icinga/icingaweb2-module-director)

We run our tests against MySQL and PostgreSQL, with PHP versions ranging from
5.3 to 7.1, including nightly builds.
![Build Status](https://github.com/Icinga/icingaweb2-module-director/workflows/PHP%20Tests/badge.svg?branch=master)

### Tests for supported Platforms

Expand Down
1 change: 0 additions & 1 deletion library/Director/Filter/CidrExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public function __construct($column, $sign, $expression)
{
if ($parts = static::splitOptionalCidrString($expression)) {
list($this->networkAddress, $this->broadcastAddress) = $parts;

} else {
throw new InvalidArgumentException("'$expression' isn't valid CIDR notation");
}
Expand Down
9 changes: 6 additions & 3 deletions library/Director/Test/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
use Icinga\Module\Director\Db\Migrations;
use Icinga\Module\Director\Objects\IcingaObject;
use Icinga\Module\Director\Objects\IcingaZone;
use PHPUnit_Framework_TestCase;
use PHPUnit\Framework\TestCase;

abstract class BaseTestCase extends PHPUnit_Framework_TestCase
abstract class BaseTestCase extends TestCase
{
private static $app;

/** @var Db */
private static $db;

public function setUp()
public function setUp(): void
{
$this->app();
}
Expand Down Expand Up @@ -69,6 +69,9 @@ protected static function getDb()
if (array_key_exists('DIRECTOR_TESTDB_HOST', $_SERVER)) {
$dbConfig->host = $_SERVER['DIRECTOR_TESTDB_HOST'];
}
if (array_key_exists('DIRECTOR_TESTDB_PORT', $_SERVER)) {
$dbConfig->port = $_SERVER['DIRECTOR_TESTDB_PORT'];
}
if (array_key_exists('DIRECTOR_TESTDB_USER', $_SERVER)) {
$dbConfig->username = $_SERVER['DIRECTOR_TESTDB_USER'];
}
Expand Down
2 changes: 1 addition & 1 deletion library/Director/Test/IcingaObjectTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function prepareObjectTearDown(IcingaObject $object)
/**
* @inheritdoc
*/
public function tearDown()
public function tearDown(): void
{
if ($this->hasDb()) {
/** @var IcingaObject $object */
Expand Down
4 changes: 2 additions & 2 deletions library/Director/Test/SyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class SyncTest extends BaseTestCase
/** @var Sync */
protected $sync;

public function setUp()
public function setUp(): void
{
$this->source = ImportSource::create(array(
'source_name' => 'testimport',
Expand All @@ -49,7 +49,7 @@ public function setUp()
$this->sync = new Sync($this->rule);
}

public function tearDown()
public function tearDown(): void
{
// properties should be deleted automatically
if ($this->rule !== null && $this->rule->hasBeenLoadedFromDb()) {
Expand Down
2 changes: 1 addition & 1 deletion test/php/library/Director/Data/AssignFilterHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AssignFilterHelperTest extends BaseTestCase
{
protected static $exampleHost;

public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
self::$exampleHost = (object) [
'address' => '127.0.0.1',
Expand Down
5 changes: 2 additions & 3 deletions test/php/library/Director/Data/RecursiveUtf8ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@

class RecursiveUtf8ValidatorTest extends BaseTestCase
{
/**
* @expectedException \InvalidArgumentException
*/
public function testDetectInvalidUtf8Character()
{
$this->expectException(\InvalidArgumentException::class);

RecursiveUtf8Validator::validateRows([
(object) [
'name' => 'test 1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ public function testWhetherIntervalStringIsCorrectlyParsed()
$this->assertEquals(c::parseInterval('1h 5m 60s'), 3960);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testWhetherInvalidIntervalStringRaisesException()
{
$this->expectException(\InvalidArgumentException::class);

c::parseInterval('1h 5m 60x');
}

Expand Down
14 changes: 7 additions & 7 deletions test/php/library/Director/IcingaConfig/StateFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Tests\Icinga\Module\Director\IcingaConfig;

use Icinga\Exception\InvalidPropertyException;
use Icinga\Exception\ProgrammingError;
use Icinga\Module\Director\IcingaConfig\StateFilterSet;
use Icinga\Module\Director\Objects\IcingaUser;
use Icinga\Module\Director\Test\BaseTestCase;
Expand All @@ -23,19 +25,17 @@ public function testIsEmptyForAnUnstoredUser()
);
}

/**
* @expectedException \Icinga\Exception\InvalidPropertyException
*/
public function testFailsForInvalidProperties()
{
$this->expectException(InvalidPropertyException::class);

$set = new StateFilterSet('bla');
}

/**
* @expectedException \Icinga\Exception\ProgrammingError
*/
public function testCannotBeStoredForAnUnstoredUser()
{
$this->expectException(ProgrammingError::class);

StateFilterSet::forIcingaObject(
$this->user1(),
'states'
Expand Down Expand Up @@ -152,7 +152,7 @@ protected function user2()
));
}

public function tearDown()
public function tearDown(): void
{
if ($this->hasDb()) {
$users = array(
Expand Down
2 changes: 1 addition & 1 deletion test/php/library/Director/Import/HostSyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ protected function removeGroups($names)
}
}

public function tearDown()
public function tearDown(): void
{
$this->removeGroups(['SYNCTEST_groupa', 'SYNCTEST_groupb']);
parent::tearDown();
Expand Down
Loading

0 comments on commit 079bf87

Please sign in to comment.