-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace deprecated usage of
CRM_Core_BAO_Setting
Additionally add configuration for phpcs, phpstan, and phpunit and a first test.
- Loading branch information
Dominic Tubach
committed
Apr 18, 2024
1 parent
39e2a61
commit c9da518
Showing
30 changed files
with
2,070 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: PHP_CodeSniffer | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- '**.php' | ||
- tools/phpcs/composer.json | ||
- phpcs.xml.dist | ||
|
||
jobs: | ||
phpcs: | ||
runs-on: ubuntu-latest | ||
name: PHP_CodeSniffer | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.3 | ||
coverage: none | ||
tools: cs2pr | ||
env: | ||
fail-fast: true | ||
|
||
- name: Get composer cache directory | ||
id: composer-cache | ||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('tools/phpcs/composer.json') }} | ||
restore-keys: ${{ runner.os }}-composer- | ||
|
||
- name: Install dependencies | ||
run: composer composer-phpcs -- update --no-progress --prefer-dist | ||
|
||
- name: Run PHP_CodeSniffer | ||
run: composer phpcs -- -q --report=checkstyle | cs2pr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: PHPStan | ||
|
||
on: | ||
push: | ||
pull_request: | ||
- '**.php' | ||
- composer.json | ||
- tools/phpstan/composer.json | ||
- ci/composer.json | ||
- phpstan.ci.neon | ||
- phpstan.neon.dist | ||
|
||
jobs: | ||
phpstan: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php-versions: ['7.4', '8.0', '8.3'] | ||
prefer: ['prefer-stable', 'prefer-lowest'] | ||
name: PHPStan with PHP ${{ matrix.php-versions }} ${{ matrix.prefer }} | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-versions }} | ||
coverage: none | ||
env: | ||
fail-fast: true | ||
|
||
- name: Get composer cache directory | ||
id: composer-cache | ||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ matrix.prefer }}-${{ hashFiles('**/composer.json') }} | ||
restore-keys: ${{ runner.os }}-composer-${{ matrix.prefer }}- | ||
|
||
- name: Install dependencies | ||
run: | | ||
git clone --depth=1 https://github.com/systopia/activity-entity.git ../activity-entity && | ||
git clone --depth=1 https://github.com/systopia/de.systopia.civioffice.git ../de.systopia.civioffice && | ||
git clone --depth=1 https://github.com/systopia/de.systopia.remotetools.git ../de.systopia.remotetools && | ||
git clone --depth=1 https://github.com/systopia/external-file.git ../external-file && | ||
composer update --no-progress --prefer-dist --${{ matrix.prefer }} --optimize-autoloader --ignore-platform-req=ext-gd && | ||
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=../de.systopia.remotetools update --no-progress --prefer-dist --${{ matrix.prefer }} --optimize-autoloader | ||
- name: Run PHPStan | ||
run: composer phpstan -- analyse -c phpstan.ci.neon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: PHPUnit | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- '**.php' | ||
- composer.json | ||
- tools/phpunit/composer.json | ||
- phpunit.xml.dist | ||
|
||
env: | ||
# On github CI machine creating the "/vendor" volume fails otherwise with: read-only file system: unknown | ||
BIND_VOLUME_PERMISSIONS: rw | ||
|
||
jobs: | ||
phpunit: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
civicrm-image-tags: [ '5-drupal', '5.38-drupal-php8.0' ] | ||
name: PHPUnit with Docker image michaelmcandrew/civicrm:${{ matrix.civicrm-image-tags }} | ||
env: | ||
CIVICRM_IMAGE_TAG: ${{ matrix.civicrm-image-tags }} | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Pull images | ||
run: docker compose -f tests/docker-compose.yml pull --quiet | ||
- name: Start containers | ||
run: docker compose -f tests/docker-compose.yml up -d | ||
- name: Prepare environment | ||
run: docker compose -f tests/docker-compose.yml exec civicrm sites/default/files/civicrm/ext/de.systopia.moregreetings/tests/docker-prepare.sh | ||
- name: Run PHPUnit | ||
run: docker compose -f tests/docker-compose.yml exec civicrm sites/default/files/civicrm/ext/de.systopia.moregreetings/tests/docker-phpunit.sh | ||
- name: Remove containers | ||
run: docker compose -f tests/docker-compose.yml down -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/.phpcs.cache | ||
/.phpunit.result.cache | ||
/.phpstan/ | ||
/phpstan.neon | ||
/tools/*/vendor/ | ||
/tools/*/composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
The dependencies specified in composer.json of this directory are required to | ||
run phpstan in CI. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"config": { | ||
"allow-plugins": { | ||
"civicrm/composer-compile-plugin": false, | ||
"civicrm/composer-downloads-plugin": true, | ||
"cweagans/composer-patches": true | ||
} | ||
}, | ||
"require": { | ||
"civicrm/civicrm-core": "^5.38" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "systopia/de.systopia.moregreetings", | ||
"type": "civicrm-ext", | ||
"license": "AGPL-3.0-or-later", | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"require": {}, | ||
"scripts": { | ||
"composer-phpcs": [ | ||
"@composer --working-dir=tools/phpcs" | ||
], | ||
"composer-phpstan": [ | ||
"@composer --working-dir=tools/phpstan" | ||
], | ||
"composer-phpunit": [ | ||
"@composer --working-dir=tools/phpunit" | ||
], | ||
"composer-tools": [ | ||
"@composer-phpcs", | ||
"@composer-phpstan", | ||
"@composer-phpunit" | ||
], | ||
"phpcs": [ | ||
"@php tools/phpcs/vendor/bin/phpcs" | ||
], | ||
"phpcbf": [ | ||
"@php tools/phpcs/vendor/bin/phpcbf" | ||
], | ||
"phpstan": [ | ||
"@php tools/phpstan/vendor/bin/phpstan" | ||
], | ||
"phpunit": [ | ||
"@php tools/phpunit/vendor/bin/simple-phpunit --coverage-text" | ||
], | ||
"test": [ | ||
"@phpcs", | ||
"@phpstan", | ||
"@phpunit" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?xml version="1.0"?> | ||
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="CiviCRM - PHPStan" | ||
xsi:noNamespaceSchemaLocation="tools/phpcs/vendor/squizlabs/php_codesniffer/phpcs.xsd"> | ||
<description>CiviCRM coding standard with support for PHPStan type hints and some additional rules</description> | ||
|
||
<!-- TODO: Commented paths should be commented in. --> | ||
<!--<file>api</file>--> | ||
<!--<file>CRM</file>--> | ||
<file>tests</file> | ||
<!--<file>moregreetings.php</file>--> | ||
|
||
<arg name="extensions" value="php"/> | ||
<arg name="cache" value=".phpcs.cache"/> | ||
<arg name="colors"/> | ||
<arg value="sp"/> | ||
|
||
<!-- Exit with code 0 if warnings, but no error occurred --> | ||
<config name="ignore_warnings_on_exit" value="true"/> | ||
|
||
<rule ref="tools/phpcs/vendor/drupal/coder/coder_sniffer/Drupal"> | ||
<!-- Conflicts with PHPStan type hints --> | ||
<exclude name="Drupal.Commenting.VariableComment.IncorrectVarType"/> | ||
<exclude name="Drupal.Commenting.FunctionComment.ParamTypeSpaces"/> | ||
<exclude name="Drupal.Commenting.VariableComment.MissingVar"/> | ||
|
||
<!-- Don't enforce phpdoc type hint because it (might) only duplicate a PHP type hint --> | ||
<exclude name="Drupal.Commenting.FunctionComment.ParamMissingDefinition"/> | ||
|
||
<!-- False positive when license header is set and variable has no comment --> | ||
<exclude name="Drupal.Commenting.VariableComment.WrongStyle"/> | ||
|
||
<exclude name="Drupal.Commenting.VariableComment.MissingVar"/> | ||
</rule> | ||
|
||
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/> | ||
<rule ref="Generic.CodeAnalysis.EmptyStatement"> | ||
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedCatch"/> | ||
</rule> | ||
<rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall"/> | ||
<rule ref="Generic.Files.OneClassPerFile"/> | ||
<rule ref="Generic.Files.OneInterfacePerFile"/> | ||
<rule ref="Generic.Files.OneObjectStructurePerFile"/> | ||
<rule ref="Generic.Files.OneTraitPerFile"/> | ||
<rule ref="Generic.Formatting.DisallowMultipleStatements"/> | ||
<rule ref="Generic.Metrics.CyclomaticComplexity"/> | ||
<rule ref="Generic.Metrics.NestingLevel"/> | ||
<rule ref="Generic.NamingConventions.AbstractClassNamePrefix"/> | ||
<rule ref="Generic.NamingConventions.InterfaceNameSuffix"/> | ||
<rule ref="Generic.NamingConventions.TraitNameSuffix"/> | ||
<rule ref="Generic.PHP.RequireStrictTypes"/> | ||
<rule ref="PSR1.Files.SideEffects"/> | ||
<rule ref="PSR12.Classes.ClassInstantiation"/> | ||
<rule ref="PSR12.Properties.ConstantVisibility"/> | ||
<rule ref="Squiz.PHP.CommentedOutCode"/> | ||
<rule ref="Squiz.PHP.GlobalKeyword"/> | ||
<rule ref="Squiz.Strings.DoubleQuoteUsage"> | ||
<exclude name="Squiz.Strings.DoubleQuoteUsage.ContainsVar"/> | ||
</rule> | ||
|
||
<!-- Lines can be 120 chars long, but never show errors --> | ||
<rule ref="Generic.Files.LineLength"> | ||
<properties> | ||
<property name="lineLimit" value="120"/> | ||
<property name="absoluteLineLimit" value="0"/> | ||
</properties> | ||
</rule> | ||
|
||
<!-- Ban some functions --> | ||
<rule ref="Generic.PHP.ForbiddenFunctions"> | ||
<properties> | ||
<property name="forbiddenFunctions" type="array"> | ||
<element key="sizeof" value="count"/> | ||
<element key="delete" value="unset"/> | ||
<element key="print" value="echo"/> | ||
<element key="is_null" value="null"/> | ||
<element key="create_function" value="null"/> | ||
</property> | ||
</properties> | ||
</rule> | ||
</ruleset> |
Oops, something went wrong.