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 Oct 1, 2024
1 parent a6dcbd0 commit 08aa3c1
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.3
coverage: none
tools: cs2pr
env:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@php tools/phpcs/vendor/bin/phpcbf"
],
"phpstan": [
"@php tools/phpstan/vendor/bin/phpstan"
"@php tools/phpstan/vendor/bin/phpstan -v"
],
"phpunit": [
"@php tools/phpunit/vendor/bin/simple-phpunit --coverage-text"
Expand Down
3 changes: 2 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ parameters:
checkTooWideReturnTypesInProtectedAndPublicMethods: true
checkUninitializedProperties: true
checkMissingCallableSignature: true
checkGenericClassInNonGenericObjectType: false
treatPhpDocTypesAsCertain: false
exceptions:
check:
Expand All @@ -39,6 +38,8 @@ parameters:
ignoreErrors:
# Note paths are prefixed with "*/" to work with inspections in PHPStorm because of:
# https://youtrack.jetbrains.com/issue/WI-63891/PHPStan-ignoreErrors-configuration-isnt-working-with-inspections
-
identifier: missingType.generics

- '#^Method Civi\\RemoteTools\\Api4\\Action\\[^\s]+Action::getHandlerResult\(\) has Civi\\RemoteTools\\Exception\\ActionHandlerNotFoundException in PHPDoc @throws tag but it.s not thrown.$#'
- '#^Method Civi\\RemoteTools\\Api4\\Api4::createAction\(\) should return Civi\\Api4\\Generic\\AbstractAction but returns array|Civi\Api4\Generic\AbstractAction.$#'
Expand Down
23 changes: 13 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
<?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"/>
<!-- Currently nikic/php-parser version 5 conflicts with version 4 used by Drupal components. -->
<env name="SYMFONY_PHPUNIT_REQUIRE" value="dms/phpunit-arraysubset-asserts:^0.5 nikic/php-parser:^4" />
</php>

<testsuites>
<testsuite name="Remote Tools Test Suite">
<testsuite name="de.systopia.remotetools 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/Remotetools/DAO</directory>
</exclude>
</whitelist>
</filter>
</include>
<exclude>
<directory>CRM/Remotetools/DAO</directory>
</exclude>
</coverage>

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

</phpunit>
1 change: 0 additions & 1 deletion tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3"
services:
civicrm:
image: michaelmcandrew/civicrm:${CIVICRM_IMAGE_TAG:-5-drupal}
Expand Down
31 changes: 28 additions & 3 deletions tests/phpunit/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);

use Civi\RemoteTools\EntityProfile\TestRemoteGroupReadOnlyEntityProfile;
use Civi\RemoteTools\EntityProfile\TestRemoteGroupReadWriteEntityProfile;
Expand All @@ -7,10 +8,33 @@

ini_set('memory_limit', '2G');

if (file_exists(__DIR__ . '/bootstrap.local.php')) {
require_once __DIR__ . '/bootstrap.local.php';
}

/*
* The return value of this function call is used in the strftime()
* implementation used in CiviCRM. If it is 'C' this results in this error:
* datefmt_create: invalid locale: U_ILLEGAL_ARGUMENT_ERROR
*
* Patch applied by CiviCRM containing strftime():
* https://patch-diff.githubusercontent.com/raw/pear/Log/pull/23.patch
*
* https://lab.civicrm.org/dev/core/-/issues/4739
* Fixed in 5.67.0 https://github.com/civicrm/civicrm-core/pull/27981
*/
if ('C' === setlocale(LC_TIME, '0')) {
setlocale(LC_TIME, 'en_US.UTF-8');
}

// phpcs:disable Drupal.Functions.DiscouragedFunctions.Discouraged
eval(cv('php:boot --level=classloader', 'phpcode'));
// phpcs:enable

if (file_exists(__DIR__ . '/../../vendor/autoload.php')) {
require_once __DIR__ . '/../../vendor/autoload.php';
}

// Make CRM_Remotetools_ExtensionUtil available.
require_once __DIR__ . '/../../remotetools.civix.php';

Expand Down Expand Up @@ -83,7 +107,7 @@ function cv(string $cmd, string $decode = 'json') {
$result = stream_get_contents($pipes[1]);
fclose($pipes[1]);
if (proc_close($process) !== 0) {
throw new RuntimeException("Command failed ($cmd):\n$result");
throw new \RuntimeException("Command failed ($cmd):\n$result");
}
switch ($decode) {
case 'raw':
Expand All @@ -92,14 +116,15 @@ function cv(string $cmd, string $decode = 'json') {
case 'phpcode':
// If the last output is /*PHPCODE*/, then we managed to complete execution.
if (substr(trim($result), 0, 12) !== '/*BEGINPHP*/' || substr(trim($result), -10) !== '/*ENDPHP*/') {
throw new RuntimeException("Command failed ($cmd):\n$result");
throw new \RuntimeException("Command failed ($cmd):\n$result");
}
return $result;

case 'json':
return json_decode($result, TRUE);

default:
throw new RuntimeException("Bad decoder format ($decode)");
throw new \RuntimeException("Bad decoder format ($decode)");
}
}

2 changes: 1 addition & 1 deletion tools/phpstan/composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"require": {
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.7",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/phpstan-strict-rules": "^1.2",
Expand Down

0 comments on commit 08aa3c1

Please sign in to comment.