From fe2760ccbac8567535876b6168fe3aea0fe81842 Mon Sep 17 00:00:00 2001 From: Dominic Tubach Date: Tue, 10 Sep 2024 15:50:37 +0200 Subject: [PATCH] chore: Update phpcs, phpstan, and phpunit related files --- .github/workflows/phpstan.yml | 4 ++-- phpcs.xml.dist | 2 +- phpstan.neon.dist | 4 +++- phpstanBootstrap.php | 6 +++++- phpunit.xml.dist | 23 +++++++++++++---------- tests/docker-phpunit.sh | 13 +++++++++++++ tests/docker-prepare.sh | 12 +++++++++--- 7 files changed, 46 insertions(+), 18 deletions(-) diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 8c57cb4..92ba9ec 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -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 diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 1654dca..11584c1 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -7,7 +7,7 @@ tests remote_case.php - /CRM/Remotecase/DAO/.*\.php$ + /CRM/RemoteCase/DAO/.*\.php$ diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ffa0643..df95c4b 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -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 @@ -19,6 +19,8 @@ parameters: level: 9 universalObjectCratesClasses: - Civi\Core\Event\GenericHookEvent + - CRM_Core_Config + - CRM_Core_DAO checkTooWideReturnTypesInProtectedAndPublicMethods: true checkUninitializedProperties: true checkMissingCallableSignature: true diff --git a/phpstanBootstrap.php b/phpstanBootstrap.php index f932196..67ad97d 100644 --- a/phpstanBootstrap.php +++ b/phpstanBootstrap.php @@ -1,6 +1,6 @@ - + - + ./tests/phpunit - - + + + api CRM Civi - - CRM/Remotecase/DAO - - - + + + CRM/RemoteCase/DAO + + + + diff --git a/tests/docker-phpunit.sh b/tests/docker-phpunit.sh index 2b0fc69..b340445 100755 --- a/tests/docker-phpunit.sh +++ b/tests/docker-phpunit.sh @@ -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 diff --git a/tests/docker-prepare.sh b/tests/docker-prepare.sh index a8738f4..10cc0c1 100755 --- a/tests/docker-prepare.sh +++ b/tests/docker-prepare.sh @@ -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"