Skip to content

Commit

Permalink
chore: Update phpcs, phpstan, and phpunit related files
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic Tubach committed Sep 10, 2024
1 parent a6dcedb commit fe2760c
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ jobs:
- name: Install dependencies
run: |
git clone --depth=1 https://github.com/systopia/de.systopia.remotetools.git ../de.systopia.remotetools &&
composer update --no-progress --prefer-dist --${{ matrix.prefer }} &&
composer update --no-progress --prefer-dist --${{ matrix.prefer }} --optimize-autoloader &&
composer composer-phpunit -- update --no-progress --prefer-dist &&
composer composer-phpstan -- update --no-progress --prefer-dist --optimize-autoloader &&
composer --working-dir=ci update --no-progress --prefer-dist --${{ matrix.prefer }} --optimize-autoloader --ignore-platform-req=ext-gd
composer --working-dir=ci update --no-progress --prefer-dist --${{ matrix.prefer }} --ignore-platform-req=ext-gd
- name: Run PHPStan
run: composer phpstan -- analyse -c phpstan.ci.neon
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<file>tests</file>
<file>remote_case.php</file>

<exclude-pattern>/CRM/Remotecase/DAO/.*\.php$</exclude-pattern>
<exclude-pattern>/CRM/RemoteCase/DAO/.*\.php$</exclude-pattern>

<arg name="extensions" value="php"/>
<arg name="cache" value=".phpcs.cache"/>
Expand Down
4 changes: 3 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ parameters:
- remote_case.php
excludePaths:
analyse:
- CRM/Remotecase/DAO/*
- CRM/RemoteCase/DAO/*
- tests/phpunit/bootstrap.php
scanFiles:
- remote_case.civix.php
Expand All @@ -19,6 +19,8 @@ parameters:
level: 9
universalObjectCratesClasses:
- Civi\Core\Event\GenericHookEvent
- CRM_Core_Config
- CRM_Core_DAO
checkTooWideReturnTypesInProtectedAndPublicMethods: true
checkUninitializedProperties: true
checkMissingCallableSignature: true
Expand Down
6 changes: 5 additions & 1 deletion phpstanBootstrap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (C) 2024 SYSTOPIA GmbH
* Copyright (C) 2022 SYSTOPIA GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -41,3 +41,7 @@
}
}
}

if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
}
23 changes: 13 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
colors="true"
failOnRisky="true"
failOnWarning="true"
forceCoversAnnotation="true"
bootstrap="tests/phpunit/bootstrap.php">

<php>
<ini name="error_reporting" value="-1" />
<ini name="error_reporting" value="-1"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=0&amp;baselineFile=./tests/ignored-deprecations.json"/>
</php>

<testsuites>
<testsuite name="Extension Test Suite">
<testsuite name="remote_case Test Suite">
<directory>./tests/phpunit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>

<coverage>
<include>
<directory suffix=".php">api</directory>
<directory suffix=".php">CRM</directory>
<directory suffix=".php">Civi</directory>
<exclude>
<directory>CRM/Remotecase/DAO</directory>
</exclude>
</whitelist>
</filter>
</include>
<exclude>
<directory>CRM/RemoteCase/DAO</directory>
</exclude>
</coverage>

<listeners>
<listener class="Civi\Test\CiviTestListener">
<arguments/>
</listener>
</listeners>

</phpunit>
13 changes: 13 additions & 0 deletions tests/docker-phpunit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ if [ ! -e tools/phpunit/vendor/bin ]; then
"$SCRIPT_DIR/docker-prepare.sh"
fi

# CIVICRM_SMARTY_AUTOLOAD_PATH is not set in the container's civicrm.settings.php so we have to do it here.
# Otherwise this results in this error:
# Fatal error: Cannot declare class Smarty, because the name is already in use in /var/www/html/sites/all/modules/civicrm/packages/smarty5/Smarty.php on line 4
# With CiviCRM 5.75 this would result in this error: Plugin tag 'localize' already registered
if ! cv vars:show --out=shell | grep -q "^CIVI_VERSION='5\.75\."; then
smarty=$(printf '%s\n' /var/www/html/sites/all/modules/civicrm/packages/smarty* | sort -r | head -n1)
if [ -e "$smarty/Smarty.php" ]; then
export CIVICRM_SMARTY_AUTOLOAD_PATH="$smarty/Smarty.php"
elif [ -e "$smarty/vendor/autoload.php" ]; then
export CIVICRM_SMARTY_AUTOLOAD_PATH="$smarty/vendor/autoload.php"
fi
fi

export XDEBUG_MODE=coverage
# TODO: Remove when not needed, anymore.
# In Docker container with CiviCRM 5.5? all deprecations are reported as direct
Expand Down
12 changes: 9 additions & 3 deletions tests/docker-prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,24 @@ else
# The autoloader expected class "Civi\ActionSchedule\Mapping" to be defined in
# file "[...]/Civi/ActionSchedule/Mapping.php". The file was found but the
# class was not in it, the class name or namespace probably has a typo.
rm -f /var/www/html/sites/all/modules/civicrm/Civi/ActionSchedule/Mapping.php
#
# Necessary for CiviCRM 5.66.0 - 5.74.x.
# https://github.com/civicrm/civicrm-core/blob/5.66.0/Civi/ActionSchedule/Mapping.php
if [ -e /var/www/html/sites/all/modules/civicrm/Civi/ActionSchedule/Mapping.php ] \
&& grep -q '// Empty file' /var/www/html/sites/all/modules/civicrm/Civi/ActionSchedule/Mapping.php; then
rm /var/www/html/sites/all/modules/civicrm/Civi/ActionSchedule/Mapping.php
fi

cv ext:download "de.systopia.xcm@https://github.com/systopia/de.systopia.xcm/releases/download/$XCM_VERSION/de.systopia.xcm-$XCM_VERSION.zip"
cv ext:download "de.systopia.identitytracker@https://github.com/systopia/de.systopia.identitytracker/archive/refs/heads/$IDENTITYTRACKER_BRANCH.zip"
cv ext:download "de.systopia.remotetools@https://github.com/systopia/de.systopia.remotetools/archive/refs/heads/$REMOTETOOLS_BRANCH.zip"
composer --working-dir="$EXT_DIR/../de.systopia.remotetools" update --no-dev --no-progress --prefer-dist --optimize-autoloader

cv ext:enable "$EXT_NAME"

# For headless tests these files need to exist.
touch /var/www/html/sites/all/modules/civicrm/sql/test_data.mysql
touch /var/www/html/sites/all/modules/civicrm/sql/test_data_second_domain.mysql

cv ext:enable "$EXT_NAME"
fi

cd "$EXT_DIR"
Expand Down

0 comments on commit fe2760c

Please sign in to comment.