Skip to content

Commit

Permalink
Use global plugin CI configuration and add PHPStan checks
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher authored Nov 8, 2023
1 parent a3506fe commit 900724c
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 109 deletions.
6 changes: 0 additions & 6 deletions .github/actions/init_containers-start.sh

This file was deleted.

8 changes: 0 additions & 8 deletions .github/actions/install.sh

This file was deleted.

5 changes: 0 additions & 5 deletions .github/actions/lint.sh

This file was deleted.

3 changes: 0 additions & 3 deletions .github/actions/teardown_containers-cleanup.sh

This file was deleted.

2 changes: 0 additions & 2 deletions .github/actions/tests.sh

This file was deleted.

98 changes: 15 additions & 83 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,93 +8,25 @@ on:
tags:
- "*"
pull_request:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
lint:
name: "Lint"
runs-on: "ubuntu-latest"
ci:
name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}"
strategy:
fail-fast: false
matrix:
include:
- {php-version: "7.4"}
steps:
- name: "Checkout"
uses: "actions/checkout@v3"

- name: "Setup PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: "none"
tools: "composer, cs2pr"
- name: "Get Composer cache directory"
id: "composer-cache"
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: "Restore dependencies cache"
uses: "actions/cache@v3"
with:
path: "${{ steps.composer-cache.outputs.dir }}"
key: "${{ github.job }}-${{ matrix.php-version }}-dependencies-${{ hashFiles('**/composer.lock') }}"

- name: "Install Composer dependencies"
run: |
composer install --ansi --no-interaction --no-progress --prefer-dist
- name: "PHP Parallel Lint"
run: |
vendor/bin/parallel-lint --colors --checkstyle --exclude ./vendor/ . | cs2pr
- name: "PHP_CodeSniffer"
run: |
vendor/bin/phpcs -q --report=checkstyle | cs2pr
- name: "Check for missing/outdated headers"
run: |
vendor/bin/licence-headers-check --ansi --no-interaction
unit-tests:
name: "unit-tests"
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
include:
- {php-version: "7.4"}
steps:
- name: "Clean workspace"
run: |
echo "APP_CONTAINER_HOME=${{ runner.temp }}/app_home" >> $GITHUB_ENV
rm -rf "${{ env.APPLICATION_ROOT }}/*"
- name: "Checkout"
uses: "actions/checkout@v3"

- name: "Initialize containers"
run: |
.github/actions/init_containers-start.sh
- name: Cache Composer dependencies
uses: actions/cache@v3
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- name: "Install dependencies"
uses: "ramsey/composer-install@v2"

- name: "Install GLPI & plugin"
run: |
.github/actions/install.sh
- name: "Run PHPUnit"
run: |
.github/actions/tests.sh
- name: "Cleanup containers"
if: always()
run: |
${{ github.workspace }}/.github/actions/teardown_containers-cleanup.sh
- {glpi-version: "10.0.x", php-version: "7.4", db-image: "mysql:5.7"}
- {glpi-version: "10.0.x", php-version: "8.0", db-image: "mysql:8.0"}
- {glpi-version: "10.0.x", php-version: "8.1", db-image: "mariadb:10.2"}
- {glpi-version: "10.0.x", php-version: "8.2", db-image: "mariadb:11.0"}
- {glpi-version: "10.0.x", php-version: "8.3-rc", db-image: "mysql:8.0"}
uses: "glpi-project/plugin-ci-workflows/.github/workflows/continuous-integration.yml@v1"
with:
plugin-key: "centreon"
glpi-version: "${{ matrix.glpi-version }}"
php-version: "${{ matrix.php-version }}"
db-image: "${{ matrix.db-image }}"
2 changes: 1 addition & 1 deletion ajax/setDowntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

header("Content-Type: text/html; charset=UTF-8");

if (isset($_POST)) {
if (isset($_POST['params'])) {
$params = $_POST['params'];
$hostid = (int) $_POST['hostid'];
$host = new Host();
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"guzzlehttp/guzzle": "^7.0"
},
"require-dev": {
"glpi-project/tools": "^0.4",
"glpi-project/tools": "^0.7.1",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^3.7"
},
Expand Down
2 changes: 2 additions & 0 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*/
function plugin_centreon_install()
{
/** @var DBmysql $DB */
global $DB;

$default_charset = DBConnection::getDefaultCharset();
Expand Down Expand Up @@ -72,6 +73,7 @@ function plugin_centreon_install()
*/
function plugin_centreon_uninstall()
{
/** @var DBmysql $DB */
global $DB;

$tables = [GlpiPlugin\Centreon\Host::getTable(),];
Expand Down
19 changes: 19 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
parameters:
parallel:
maximumNumberOfProcesses: 2
level: 2
bootstrapFiles:
- ../../inc/based_config.php
paths:
- src
- front
- ajax
- hook.php
- setup.php
scanDirectories:
- ../../inc
- ../../src
stubFiles:
- ../../stubs/glpi_constants.php
rules:
- GlpiProject\Tools\PHPStan\Rules\GlobalVarTypeRule
9 changes: 9 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="tests/bootstrap.php" colors="true" testdox="true">
<testsuites>
<testsuite name="Plugin test suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
1 change: 1 addition & 0 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
*/
function plugin_init_centreon()
{
/** @var array $PLUGIN_HOOKS */
global $PLUGIN_HOOKS;

$PLUGIN_HOOKS['csrf_compliant']['centreon'] = true;
Expand Down
1 change: 1 addition & 0 deletions src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function connectionRequest(array $params = [])

public function diagnostic()
{
$result = [];
try {
$test = $this->connectionRequest(['throw' => true]);

Expand Down
1 change: 1 addition & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static function displayTabContentForItem(

public static function showForConfig(\Config $config, $withtemplate = 0)
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;

if (!self::canView()) {
Expand Down
1 change: 1 addition & 0 deletions src/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function hostList()
if ($res["security"]["token"] != null) {
$list = $api->getHostsList();
if ($list != null) {
$items_centreon = [];
foreach ($list["result"] as $item_centreon) {
$items_centreon[] = [
'centreon_id' => $item_centreon["id"],
Expand Down

0 comments on commit 900724c

Please sign in to comment.