Skip to content

Commit 8e8ce38

Browse files
committed
Fix various issues for extension projects.
1 parent 880c421 commit 8e8ce38

File tree

10 files changed

+68
-63
lines changed

10 files changed

+68
-63
lines changed

README.md

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,45 @@ For an extension:
3434
}
3535
```
3636

37-
For an extension (to check only for D9 deprecations):
38-
39-
```json
40-
"grumphp": {
41-
"config-default-path": "vendor/digipolisgent/qa-drupal/configs/grumphp-extension-d9.yml"
42-
}
43-
```
44-
4537
Now install this package and its requirements by executing execute following command:
4638
<pre><code>composer require --dev digipolisgent/qa-drupal:^1.0</code></pre>
4739

4840

4941
# Configuration
5042

51-
**This section only applies to the site and extension configuration of GrumPHP.**
43+
## General
44+
45+
If required you can extend or override the provided configuration file of a task.
46+
Simply create the matching configuration file in the root of your project.
5247

53-
You can optionally extend or override the task configuration files by creating
54-
them in your project root. For example: create a `phpcs.xml` or `phpcs.local.xml`
55-
file to override the configuration provided by this package.
48+
For example, to override the provided `phpcs.xml` file you can either create a
49+
`phpcs.xml` or `phpcs.local.xml` file. Note that the latter one should only be
50+
used for changes that shouldn't be comitted.
5651

57-
Note that Yaml and Neon files will be merged with your local files. So if you create
58-
a `phpstan.neon` file it will be merged with the `phpstan.neon` file of this package.
52+
Yaml and Neon files will extend (merged into) the provided configuration file by default.
53+
Create a `.env` or `.env.local` file and add following contents to change this behaviour:
5954

60-
To prevent this, create a `.env` or `.env.local` file and add following contents:
6155
```
62-
PHPSTAN_SKIP_PACKAGE_GLOBAL=1
56+
[FILENAME]_SKIP_[TYPE]=1
6357
```
6458

65-
The skip variable name is always the same `[FILENAME]_SKIP_[TYPE]`, wherin `[FILENAME]`
66-
if the file name and `[TYPE]` is either:
59+
Wherein `[FILENAME]` matches the configuration filename and `[TYPE]` is either:
6760

68-
- `LOCAL` to skip `phpstan.local.neon`.
69-
- `PROJECT` to skip `phpstan.neon`.
70-
- `PACKAGE_TYPE` to skip `phpstan-extension.neon` (if in an extension) of this package.
71-
- `PACKAGE_GLOBAL` to skip `phpstan.neon` of this package.
61+
- `LOCAL` to skip for example your `phpstan.local.neon` file.
62+
- `PROJECT` to skip for example your `phpstan.neon` file.
63+
- `PACKAGE_TYPE` to skip for example the provided `phpstan-extension.neon` or `phpstan-site.neon` file.
64+
- `PACKAGE_GLOBAL` to skip for example the provided `phpstan.neon` file.
65+
66+
Other file types cannot be merged and will just override all other less specific files.
67+
68+
69+
## PHPStan in deprecations only mode
70+
71+
Create a `phpstan.neon` file and add following contents to ignore everything except deprecations.
72+
73+
```
74+
parameters:
75+
customRulesetUsed: true
76+
ignoreErrors:
77+
- '#^(?:(?!deprecated).)*$#'
78+
```

configs/grumphp-extension-d9.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

configs/grumphp-extension.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ parameters:
5050
max_body_width: 80
5151
max_subject_width: 80
5252
matchers:
53-
- "/^([A-Z]+-\\d+(, [A-Z]+-\\d+): )?(Add|Change|Fix|Update|Remove) /"
53+
- "/^([A-Z]+-\\d+(, [A-Z]+-\\d+)*: )?(Add|Change|Fix|Update|Remove) /"
5454
case_insensitive: false
5555
phpcpd:
5656
names_exclude:
@@ -93,6 +93,8 @@ parameters:
9393
phpstan:
9494
configuration: .phpstan.qa-drupal.neon
9595
level: 4
96+
ignore_patterns:
97+
- "#^tests/#"
9698
triggered_by:
9799
- php
98100
- inc

configs/phpmd.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616

1717
<rule ref="rulesets/codesize.xml">
1818
<exclude name="CyclomaticComplexity" />
19+
<exclude name="ExcessiveClassComplexity" />
1920
<exclude name="ExcessiveMethodLength" />
2021
<exclude name="ExcessiveParameterList" />
2122
<exclude name="NPathComplexity" />
23+
<exclude name="TooManyMethods" />
2224
<exclude name="TooManyPublicMethods" />
2325
</rule>
2426

configs/phpstan-extension-d9.neon

Lines changed: 0 additions & 12 deletions
This file was deleted.

configs/phpstan.neon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ parameters:
77
reportUnmatchedIgnoredErrors: false
88
ignoreErrors:
99
- '#Unsafe usage of new static\(\)#'
10-
- '#\Drupal calls should be avoided in classes#'
10+
- '#\\Drupal calls should be avoided in classes#'
11+
- '#Method Drupal\\Core\\Form\\FormBuilderInterface::getForm\(\) invoked with#'
1112
excludes_analyse:
1213
- '*/node_modules/*'

configs/phpunit-extension.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!-- TODO set checkForUnintentionallyCoveredCode="true" once https://www.drupal.org/node/2626832 is resolved. -->
3-
<phpunit bootstrap="../drupal/core/tests/bootstrap.php" colors="true"
3+
<phpunit bootstrap="../drupal/core/tests/bootstrap.php"
4+
printerClass="Drupal\Tests\Listeners\HtmlOutputPrinter"
5+
colors="true"
46
beStrictAboutTestsThatDoNotTestAnything="true"
57
beStrictAboutOutputDuringTests="true"
6-
beStrictAboutChangesToGlobalState="true"
7-
printerClass="Drupal\Tests\Listeners\HtmlOutputPrinter">
8+
beStrictAboutChangesToGlobalState="true">
89

910
<php>
1011
<ini name="error_reporting" value="32767"/>
@@ -37,11 +38,17 @@
3738
<whitelist>
3839
<directory suffix=".php">./</directory>
3940
<exclude>
41+
<directory>./vendor</directory>
4042
<directory suffix=".api.php">./</directory>
4143
<directory suffix="Test.php">./</directory>
4244
<directory suffix="TestBase.php">./</directory>
4345
<directory suffix="TestCase.php">./</directory>
4446
</exclude>
4547
</whitelist>
4648
</filter>
49+
50+
<logging>
51+
<log type="coverage-html" target="build/coverage" />
52+
<log type="coverage-clover" target="build/logs/clover.xml"/>
53+
</logging>
4754
</phpunit>

configs/phpunit-site.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!-- TODO set checkForUnintentionallyCoveredCode="true" once https://www.drupal.org/node/2626832 is resolved. -->
3-
<phpunit bootstrap="web/core/tests/bootstrap.php" colors="true"
3+
<phpunit bootstrap="web/core/tests/bootstrap.php"
4+
printerClass="Drupal\Tests\Listeners\HtmlOutputPrinter"
5+
colors="true"
46
beStrictAboutTestsThatDoNotTestAnything="true"
57
beStrictAboutOutputDuringTests="true"
6-
beStrictAboutChangesToGlobalState="true"
7-
printerClass="Drupal\Tests\Listeners\HtmlOutputPrinter">
8+
beStrictAboutChangesToGlobalState="true">
89

910
<php>
1011
<ini name="error_reporting" value="32767"/>
@@ -46,4 +47,9 @@
4647
</exclude>
4748
</whitelist>
4849
</filter>
50+
51+
<logging>
52+
<log type="coverage-html" target="build/coverage" />
53+
<log type="coverage-clover" target="build/logs/clover.xml"/>
54+
</logging>
4955
</phpunit>

src/EventSubscriber/GrumphpEventSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ protected function getTaskConfigFileInfo(TaskInterface $task)
185185
}
186186
elseif ($task instanceof Phpunit) {
187187
$info = [
188-
'filename' => 'phpmd',
188+
'filename' => 'phpunit',
189189
'extension' => 'xml',
190190
'type' => self::FILETYPE_XML,
191191
];

src/PHPUnit/TestSuites/TestSuiteBase.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ public function __construct($name, $suite_namespace)
2121
parent::__construct('', $name);
2222

2323
// Get the project root.
24-
$root = dirname(__DIR__, 6);
24+
$reflection = new \ReflectionClass(get_class($this));
25+
$root = dirname($reflection->getFileName(), 7);
2526

2627
if (!file_exists($root . '/web/index.php')) {
2728
// The project is an extension, add all tests.
2829
$this->addTestsBySuiteNamespace($root, $suite_namespace);
2930
} else {
3031
// The project is a site, add the tests of all custom extensions.
3132
$roots = [
32-
$root . '/web/modules/custom',
33-
$root . '/web/themes/custom',
34-
$root . '/web/profiles/custom',
33+
"$root/web/modules/custom",
34+
"$root/web/themes/custom",
35+
"$root/web/profiles/custom",
3536
];
3637

3738
foreach ($roots as $root) {
@@ -50,7 +51,14 @@ public function __construct($name, $suite_namespace)
5051
*/
5152
protected function addTestsBySuiteNamespace($root, $suite_namespace)
5253
{
54+
$vendor = "$root/vendor";
55+
5356
foreach (drupal_phpunit_find_extension_directories($root) as $extension_name => $dir) {
57+
if (strpos($dir, $vendor) === 0) {
58+
// Exclude the vendor directory.
59+
continue;
60+
}
61+
5462
$tests_path = "$dir/tests/src/$suite_namespace";
5563

5664
if (is_dir($tests_path)) {

0 commit comments

Comments
 (0)