Skip to content

Commit 21e2255

Browse files
author
Stefan Boonstra
committed
WIP
1 parent d1e64b5 commit 21e2255

Some content is hidden

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

50 files changed

+401
-302
lines changed

CHANGELOG.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Added
99
- Added `phpunit/phpunit` to suggested dependencies in `composer.json`.
1010
- Added `youwe/coding-standard-phpstorm` to suggested dependencies in `composer.json`.
11-
- Added support to honor upstream version constraints
11+
- Added support to honor upstream version constraints.
1212
- Github action for php 8.3 and php 8.4 to run unit tests against PHPUnit 12.
13-
- Testing suite now attempts to install phpunit upstream if it isn't available yet
14-
- Existing upstream versions are honored if already installed
15-
- Upstream projects not having phpunit installed will install phpunit with an @stable version
13+
- Testing suite now attempts to install phpunit upstream if it isn't available yet.
14+
- Existing upstream versions are honored if already installed.
15+
- Upstream projects not having phpunit installed will install phpunit with an @stable version.
16+
- Added support for Drupal configuration and templates.
1617

1718
### Changed
18-
- Unit tests as part of the testing suite are rewritten for PHPUnit 12
19+
- Unit tests as part of the testing suite are rewritten for PHPUnit 12.
1920
- Updated GitHub Action workflows to support PHP 8.1, 8.2, and 8.3.
2021
- `composer.json`: Dropped support for PHP < 8.1.
21-
- Moved phpunit from require to require-dev
22+
- Moved phpunit from require to require-dev.
2223
- Changed PHPMD suppressions in docblocks to quote the rule name, due to changes in later versions of PHPStan that create false positives on these docblocks if not quoted.
2324

2425
### Removed
2526
- Removed support for EOL PHP versions. Projects running PHP < 8.1 can stick to version 2 of the testing-suite.
2627
- Removed support for Composer 1. Projects still relying on Composer 1 can stick to version 2 of the testing-suite.
27-
- Removed `youwe/coding-standard-phpstorm` as dependency (it is still listed in suggest)
28-
- Removed `phpunit/phpunit` as direct dependency (it is still in require-dev and installed upstream through the `youwe/dependency-installer`)
29-
- Github actions for php < 8.1
28+
- Removed `youwe/coding-standard-phpstorm` as dependency (it is still listed in suggest).
29+
- Removed `phpunit/phpunit` as direct dependency (it is still in require-dev and installed upstream through the `youwe/dependency-installer`).
30+
- Github actions for php < 8.1.
31+
- Dependency on seperated coding style packages to simplify development and remove overhead.
32+
- Dropped support for Laravel and Magento 1.
3033

3134
## 2.19.1
3235
### 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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ predefined default configurations per project type.
1111

1212
## Features
1313

14-
- [Project Type detector](docs/features/project-type-detector.md)
14+
- [Project Type detector](docs/features/project-type-detection.md)
1515
- [PHP storm configuration](docs/features/php-storm-integration.md)
1616

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/components/phpcs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ During the installation of the testing suite a file called `phpcs.xml` is added
77
the root of the repository which refers to the coding standard. To make
88
adjustments to the coding standard this file can be edited and committed.
99

10-
[PHPCS](https://github.com/FriendsOfPHP/PHP-CS-Fixer)
10+
[PHPCS](https://github.com/FriendsOfPHP/PHP-CS-Fixer) \
1111
[PHP Coding Standards Fixer](https://github.com/squizlabs/PHP_CodeSniffer)
1212

1313
## Common issues

docs/examples/github-actions.md

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

3-
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.
3+
The example below will run the testing-suite inside [github actions](https://github.com/features/actions)
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/features/php-storm-integration.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# PHPStorm Integration
22

3+
### The basics
34
When the testing suite is installed in a PHPStorm environment it automatically
45
configures PHPStorm to use the correct coding style.
56

@@ -39,3 +40,8 @@ __Settings > Languages & Frameworks > Javascript > Code Quality Tools > ESLint__
3940

4041
Enable ESLint by checking `Enabled`. Then set the `Node interpreter`
4142
to `Project` and `Configuration file` to `Automatic Search`.
43+
44+
### Additional features
45+
An extra package [youwe/coding-standard-phpstorm](https://github.com/YouweGit/coding-standard-phpstorm)
46+
is available to extend phpstorm and automatically configure some of the inspection profiles,
47+
as well as extend PHPStorm with some standard (Magento 2) file templates to help with (Magento 2) boilerplate.

0 commit comments

Comments
 (0)