Skip to content

Commit c372e47

Browse files
author
Stefan Boonstra
committed
WIP
1 parent d1e64b5 commit c372e47

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+375
-283
lines changed

MIGRATION.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Testing suite v2 to v3 migration guide
2+
### 1. Double check your project type in the project composer.json.
3+
We use the project type to automatically update some ruleset mappings for PHPCS and PHPMD.
4+
5+
For a list
6+
### 2. Update to version 3
7+
When using ddev:
8+
```bash
9+
ddev composer require --dev youwe/testing-suite:^3.0 --no-update
10+
ddev composer remove --dev youwe/coding-standard youwe/coding-standard-magento2 --no-update
11+
ddev composer update youwe/testing-suite -W
12+
ddev composer install
13+
```
14+
15+
When not using ddev:
16+
```text
17+
Same as above but using local composer installation (not-recommended)
18+
```
19+
20+
### Sanity checks
21+
Check the following
22+
23+
1. The PHPCS file exists in your project root and points to the correct ruleset configuration in youwe/testing-suite
24+
2. The PHPMD file exists in your project root and points to the correct ruleset configuration in youwe/testing-suite

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ predefined default configurations per project type.
1717
## Supported project types
1818

1919
- Default (`default`)
20-
- Laravel (`laravel`)
21-
- [Magento 1](docs/project-types/magento1.md) (`magento1`)
2220
- [Magento 2](docs/project-types/magento2.md) (`magento2`)
2321
- Pimcore (`pimcore`)
22+
- Drupal (`drupal`)
2423

2524
## Included analysis tools
2625

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@
2626
"require": {
2727
"php": "^8.1",
2828
"composer-plugin-api": "^2.0",
29+
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
2930
"enlightn/security-checker": "^1.5 || ^2.0",
3031
"kint-php/kint": "@stable",
3132
"php-parallel-lint/php-parallel-lint": "^1.2",
33+
"phpmd/phpmd": "^2.15",
3234
"phpro/grumphp-shim": "^1.13",
3335
"phpstan/phpstan": "@stable",
34-
"youwe/coding-standard": "^3.5.0",
36+
"squizlabs/php_codesniffer": "^3.12.0",
3537
"youwe/composer-dependency-installer": "^1.4.0",
3638
"youwe/composer-file-installer": "^1.2.0"
3739
},

config/default/phpmd.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Youwe/Global"
3+
xmlns="http://pmd.sf.net/ruleset/1.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
6+
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
7+
<description>
8+
Global defined PHPMD rules
9+
</description>
10+
11+
<!-- Taken from Global ruleset since we can't modify a referenced rule without overwriting it completely.
12+
See: https://github.com/phpmd/phpmd/issues/39 -->
13+
<rule ref="rulesets/cleancode.xml">
14+
<!-- Even though else statements can be rewritten to be avoided, this rule to always block else statements is a bit
15+
extreme to enforce in standards. Rule can still be adopted on project-level if needed. -->
16+
<exclude name="ElseExpression"/>
17+
<!-- We should not assume all code is OOP based, and static usage is not inherently bad outside OOP/SOLID contexts. -->
18+
<exclude name="StaticAccess"/>
19+
<!-- Boolean flags are sometimes needed to preserve e.g. backwards compatibility. We don't want to enforce this in a blanket
20+
statement / default rule but if projects want to enforce this they are free to do so. -->
21+
<exclude name="BooleanArgumentFlag"/>
22+
</rule>
23+
24+
<rule ref="rulesets/codesize.xml" />
25+
<rule ref="rulesets/design.xml" />
26+
<rule ref="rulesets/unusedcode.xml" />
27+
<rule ref="rulesets/naming.xml" />
28+
29+
<rule ref="rulesets/naming.xml/LongVariable">
30+
<properties>
31+
<!-- 20 limit is hard to make descriptive, plus has historically been 30 so also for better backwards compatibility support -->
32+
<property name="maximum" value="30"/>
33+
</properties>
34+
</rule>
35+
<!-- End of global ruleset -->
36+
</ruleset>

config/default/ruleset.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Youwe/Default">
3+
<description>Youwe coding standards for code sniffing for generic platform-agnostic PHP code.</description>
4+
<!-- Show sniff codes in all reports. Easier to ignore rules when necessary -->
5+
<arg value="s"/>
6+
<!-- Use colors in output -->
7+
<arg name="colors" />
8+
9+
<!-- Base rules on PSR12 -->
10+
<rule ref="PSR12" />
11+
</ruleset>

config/drupal/grumphp.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
imports:
2+
- resource: '../default/grumphp.yml'
3+
4+
# Extend git triggers with common Drupal constructs
5+
parameters:
6+
git_blacklist.triggered_by: [ 'php', 'js', 'twig' ]

config/drupal/phpmd.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PHPMD"
3+
xmlns="http://pmd.sf.net/ruleset/1.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
6+
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
7+
<description>
8+
Global defined PHPMD rules for Drupal projects
9+
</description>
10+
<rule ref="./config/default/phpmd.xml" />
11+
12+
<!-- No overrides compared to default. Revisit this file and recreate default drupal rulesets for projects if needed.
13+
Note: seperate ruleset needed until https://github.com/phpmd/phpmd/issues/39 is resolved -->
14+
</ruleset>

config/drupal/ruleset.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Youwe/Drupal">
3+
<description>Youwe coding standard extensions for sniffing code in Drupal projects.</description>
4+
5+
<!-- Use default Youwe coding standards for PHP projects. -->
6+
<rule ref="../default" />
7+
<!-- Additional Drupal-specific rulesets. -->
8+
9+
</ruleset>

config/magento2/phpmd.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PHPMD"
3+
xmlns="http://pmd.sf.net/ruleset/1.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
6+
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
7+
<description>
8+
Global defined PHPMD rules for Magento 2 projects
9+
</description>
10+
11+
<!-- Taken from Global ruleset since we can't modify a referenced rule without overwriting it completely.
12+
See: https://github.com/phpmd/phpmd/issues/39 -->
13+
<rule ref="rulesets/cleancode.xml">
14+
<!-- Even though else statements can be rewritten to be avoided, this rule to always block else statements is a bit
15+
extreme to enforce in standards. Rule can still be adopted on project-level if needed. -->
16+
<exclude name="ElseExpression"/>
17+
<!-- We should not assume all code is OOP based, and static usage is not inherently bad outside OOP/SOLID contexts. -->
18+
<exclude name="StaticAccess"/>
19+
<!-- Boolean flags are sometimes needed to preserve e.g. backwards compatibility. We don't want to enforce this in a blanket
20+
statement / default rule but if projects want to enforce this they are free to do so. -->
21+
<exclude name="BooleanArgumentFlag"/>
22+
</rule>
23+
24+
<rule ref="rulesets/codesize.xml" />
25+
<rule ref="rulesets/design.xml" />
26+
<rule ref="rulesets/unusedcode.xml" />
27+
<rule ref="rulesets/naming.xml" />
28+
29+
<rule ref="rulesets/naming.xml/LongVariable">
30+
<properties>
31+
<!-- 20 limit is hard to make descriptive, plus has historically been 30 so also for better backwards compatibility support -->
32+
<property name="maximum" value="30"/>
33+
</properties>
34+
</rule>
35+
<!-- End of global ruleset -->
36+
37+
<!-- Increase maximum amount of coupling, because magento constructor injection can become quite extreme and is mostly an adobe issue to fix -->
38+
<rule ref="rulesets/design.xml">
39+
<exclude name="CouplingBetweenObjects"/>
40+
</rule>
41+
42+
<rule ref="rulesets/design.xml/CouplingBetweenObjects">
43+
<properties>
44+
<property name="maximum" value="20"/>
45+
</properties>
46+
</rule>
47+
48+
</ruleset>

config/magento2/ruleset.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Youwe/Magento2">
3+
<description>Youwe coding standard extensions for sniffing code in Magento 2 projects.</description>
4+
5+
<!-- Use default Youwe coding standards for PHP projects. -->
6+
<rule ref="../default" />
7+
<!-- Magento coding standards -->
8+
<rule ref="Magento2" />
9+
</ruleset>

config/pimcore/phpmd.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PHPMD"
3+
xmlns="https://pmd.sf.net/ruleset/1.0.0"
4+
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="https://pmd.sf.net/ruleset/1.0.0 https://pmd.sf.net/ruleset_xml_schema.xsd"
6+
xsi:noNamespaceSchemaLocation="https://pmd.sf.net/ruleset_xml_schema.xsd">
7+
<description>
8+
Global defined PHPMD rules for Pimcore projects
9+
</description>
10+
11+
<!-- Taken from Global ruleset since we can't modify a referenced rule without overwriting it completely.
12+
See: https://github.com/phpmd/phpmd/issues/39 -->
13+
<rule ref="rulesets/cleancode.xml">
14+
<!-- Even though else statements can be rewritten to be avoided, this rule to always block else statements is a bit
15+
extreme to enforce in standards. Rule can still be adopted on project-level if needed. -->
16+
<exclude name="ElseExpression"/>
17+
<!-- We should not assume all code is OOP based, and static usage is not inherently bad outside OOP/SOLID contexts. -->
18+
<exclude name="StaticAccess"/>
19+
<!-- Boolean flags are sometimes needed to preserve e.g. backwards compatibility. We don't want to enforce this in a blanket
20+
statement / default rule but if projects want to enforce this they are free to do so. -->
21+
<exclude name="BooleanArgumentFlag"/>
22+
</rule>
23+
24+
<rule ref="rulesets/codesize.xml" />
25+
<rule ref="rulesets/design.xml" />
26+
<rule ref="rulesets/unusedcode.xml" />
27+
<rule ref="rulesets/naming.xml" />
28+
29+
<rule ref="rulesets/naming.xml/LongVariable">
30+
<properties>
31+
<!-- 20 limit is hard to make descriptive, plus has historically been 30 so also for better backwards compatibility support -->
32+
<property name="maximum" value="30"/>
33+
</properties>
34+
</rule>
35+
<!-- End of global ruleset -->
36+
37+
<!-- up() is required for doctrine migrations when implementing the interface. -->
38+
<rule ref="rulesets/naming.xml/ShortMethodName">
39+
<properties>
40+
<property name="exceptions" value="up" />
41+
</properties>
42+
</rule>
43+
</ruleset>

config/pimcore/ruleset.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Youwe/Pimcore">
3+
<description>Youwe coding standard extensions for sniffing code in Pimcore projects.</description>
4+
5+
<!-- Use default Youwe coding standards for PHP projects. -->
6+
<rule ref="../default" />
7+
8+
<!-- Pimcore specific exclusions -->
9+
<exclude-pattern>*/bin/*</exclude-pattern>
10+
<exclude-pattern>*/install-profiles/*</exclude-pattern>
11+
<exclude-pattern>*/public/*</exclude-pattern>
12+
<exclude-pattern>*/var/*</exclude-pattern>
13+
</ruleset>

docs/examples/github-actions.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
11
# GitHub Actions
22

33
The example below will run the testing-suite inside [github actions] (https://github.com/features/actions)
4-
for both PHP 7.4 and 8.1.
4+
for PHP versions 8.1 through 8.4 and specify whether PHPUnit should also be run depending on PHP version.
55

66
```yml
77
name: Testing Suite
88
on: [push]
99
jobs:
1010
PHP:
1111
strategy:
12-
# Test with multiple PHP versions
1312
matrix:
14-
image: [
15-
'srcoder/development-php:php74-fpm',
16-
'srcoder/development-php:php81-fpm'
17-
]
13+
php-version: [8.1, 8.2, 8.3, 8.4]
1814
runs-on: ubuntu-latest
1915
container:
20-
image: ${{ matrix.image }}
16+
image: ${{ matrix.php-version == '8.1' && 'srcoder/development-php:php81-fpm' ||
17+
matrix.php-version == '8.2' && 'srcoder/development-php:php82-fpm' ||
18+
matrix.php-version == '8.3' && 'srcoder/development-php:php83-fpm' ||
19+
matrix.php-version == '8.4' && 'srcoder/development-php:php84-fpm' }}
2120
steps:
22-
# Checkout the repository
2321
- name: Checkout
2422
uses: actions/checkout@v2
25-
# Run Testing Suite
26-
- name: Testing Suite
23+
24+
- name: Install Dependencies
2725
run: |
2826
composer2 install --dev --prefer-dist --no-scripts --no-progress --optimize-autoloader --no-interaction -vvv
2927
composer2 show
30-
composer2 exec -v grumphp run
3128
shell: bash
3229

30+
- name: Run GrumPHP Tasks
31+
run: |
32+
if [[ "${{ matrix.php-version }}" == "8.1" || "${{ matrix.php-version }}" == "8.2" ]]; then
33+
composer2 exec -v grumphp -- run --tasks=composer,jsonlint,xmllint,yamllint,phpcs,phplint,phpmd,phpstan,securitychecker_enlightn
34+
else
35+
composer2 exec -v grumphp -- run
36+
fi
37+
shell: bash
38+
39+
3340
```

docs/project-types/magento1.md

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

docs/project-types/magento2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
- `magento2-project`: [Youwe Coding Standard Magento2](https://github.com/YouweGit/coding-standard-magento2)
2-
- `magento2-module`: [Youwe Coding Standard Magento2](https://github.com/YouweGit/coding-standard-magento2)
1+
- `magento2-project`: [Youwe Coding Standard Magento2](../../config/magento2)
2+
- `magento2-module`: [Youwe Coding Standard Magento2](../../config/magento2)

grumphp.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ parameters:
99
- /^phpunit.xml$/
1010
- /^pdepend.xml$/
1111
- /^templates/
12+
13+
grumphp:
14+
# Disable ddev wrapper when running grumphp of testing-suite itself.
15+
# Temp until testing-suite development is also wrapped by ddev, which is on the roadmap
16+
git_hook_variables:
17+
EXEC_GRUMPHP_COMMAND: exec

phpcs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
66
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
77
<description>PHPCS</description>
8-
<rule ref="./vendor/youwe/coding-standard/src/Global"/>
8+
<rule ref="./config/default"/>
99
<!-- Append arg -s to phpcs to display the name of failed sniffs -->
1010
<arg value="s"/>
1111
</ruleset>

phpmd.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
66
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
77
<description>PHPMD</description>
8-
<rule ref="./vendor/youwe/coding-standard/src/Global/phpmd.xml" />
8+
<rule ref="./config/default/phpmd.xml" />
99
</ruleset>

src/Factory/ProcessFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ProcessFactory implements ProcessFactoryInterface
2323
public function create(string $commandLine): Process
2424
{
2525
// See https://github.com/composer/composer/blob/1.10.17/src/Composer/Util/ProcessExecutor.php#L68:L72
26-
// @phpstan-ignore-next-line because phpstan can see it's available, but we cannot guarantee symfony >= 4.2 upstream
26+
// @phpstan-ignore-next-line because we cannot guarantee symfony >= 4.2 upstream
2727
return method_exists(Process::class, 'fromShellCommandline')
2828
? Process::fromShellCommandline($commandLine) // Symfony >= 4.2
2929
: new Process($commandLine); // Symfony < 4.2

0 commit comments

Comments
 (0)