Skip to content

Commit 4304691

Browse files
authored
V4: refactor, tests, workflow (#3)
1 parent 43fcc0a commit 4304691

30 files changed

Lines changed: 1320 additions & 117 deletions

.github/workflows/phpmd.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: PHPMD
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
phpcs:
7+
name: Mess Detector
8+
runs-on: [ubuntu-latest]
9+
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Get composer cache directory
15+
id: composer-cache
16+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
17+
18+
- name: Cache dependencies
19+
uses: actions/cache@v4
20+
with:
21+
path: ${{ steps.composer-cache.outputs.dir }}
22+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
23+
restore-keys: ${{ runner.os }}-composer-
24+
25+
- name: Install dependencies
26+
run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-*
27+
28+
- name: PHPMD
29+
run: php vendor/bin/phpmd src/ github .phpmd.dist.xml --baseline-file .phpmd.dist.baseline.xml

.github/workflows/phpstan.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: PHPStan
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
phpstan:
7+
name: Analyze
8+
runs-on: [ubuntu-latest]
9+
10+
steps:
11+
- name: Setup PHP
12+
uses: shivammathur/setup-php@v2
13+
with:
14+
php-version: 7.4
15+
16+
- uses: actions/checkout@v4
17+
18+
- name: Get composer cache directory
19+
id: composer-cache
20+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
21+
22+
- name: Cache dependencies
23+
uses: actions/cache@v4
24+
with:
25+
path: ${{ steps.composer-cache.outputs.dir }}
26+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
27+
restore-keys: ${{ runner.os }}-composer-
28+
29+
- name: Install dependencies
30+
run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-*
31+
32+
- name: Restore result cache
33+
uses: actions/cache/restore@v4
34+
with:
35+
path: .phpstan.cache
36+
key: phpstan-result-cache-${{ github.run_id }}
37+
restore-keys: |
38+
phpstan-result-cache-
39+
40+
- name: PHPStan Static Analysis
41+
run: XDEBUG_MODE=off php vendor/bin/phpstan.phar analyze
42+
43+
- name: Save result cache
44+
uses: actions/cache/save@v4
45+
if: always()
46+
with:
47+
path: .phpstan.cache
48+
key: phpstan-result-cache-${{ github.run_id }}

.github/workflows/phpunit.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: PHPUnit
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
unit-tests:
7+
runs-on: ${{ matrix.operating-system }}
8+
strategy:
9+
matrix:
10+
operating-system: [ubuntu-latest]
11+
php-versions: ['7.4', '8.3']
12+
13+
steps:
14+
- name: Setup PHP
15+
uses: shivammathur/setup-php@v2
16+
with:
17+
php-version: ${{ matrix.php-versions }}
18+
coverage: pcov #optional, setup coverage driver
19+
env:
20+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
22+
- uses: actions/checkout@v4
23+
24+
- name: Get composer cache directory
25+
id: composer-cache
26+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
27+
28+
- name: Cache dependencies
29+
uses: actions/cache@v4
30+
with:
31+
path: ${{ steps.composer-cache.outputs.dir }}
32+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
33+
restore-keys: ${{ runner.os }}-composer-
34+
35+
- name: Install dependencies
36+
run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-*
37+
38+
- name: Run phpUnit
39+
run: php vendor/bin/phpunit --configuration .phpunit.dist.xml

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/.idea
22
/vendor
3+
/.phpstan.cache
4+
/.phpunit.cache
35
.php-cs-fixer.cache
6+
.phpmd.result-cache.php
47
composer.lock

.phpmd.dist.baseline.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<phpmd-baseline>
3+
<violation rule="PHPMD\Rule\Design\WeightedMethodCount" file="src/OpenMage/ComposerPlugin/Copy/AbstractCopyPlugin.php"/>
4+
<violation rule="PHPMD\Rule\CyclomaticComplexity" file="src/OpenMage/ComposerPlugin/Copy/AbstractCopyPlugin.php" method="processComposerInstall"/>
5+
<violation rule="PHPMD\Rule\CyclomaticComplexity" file="src/OpenMage/ComposerPlugin/Copy/AbstractCopyPlugin.php" method="processUnpkgInstall"/>
6+
<violation rule="PHPMD\Rule\Design\NpathComplexity" file="src/OpenMage/ComposerPlugin/Copy/AbstractCopyPlugin.php" method="processUnpkgInstall"/>
7+
</phpmd-baseline>

.phpmd.dist.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="OpenMage ruleset"
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 https://pmd.sf.net/ruleset_xml_schema.xsd"
6+
xsi:noNamespaceSchemaLocation="https://pmd.sf.net/ruleset_xml_schema.xsd">
7+
<description>
8+
OpenMage ruleset
9+
</description>
10+
<rule ref="rulesets/unusedcode.xml" />
11+
<rule ref="rulesets/cleancode.xml" />
12+
<rule ref="rulesets/controversial.xml" />
13+
<rule ref="rulesets/naming.xml">
14+
<exclude name="ShortVariable" />
15+
</rule>
16+
<rule ref="rulesets/naming.xml/ShortVariable">
17+
<properties>
18+
<property name="exceptions" value="io" />
19+
</properties>
20+
</rule>
21+
<rule ref="rulesets/design.xml" />
22+
<rule ref="rulesets/codesize.xml" />
23+
</ruleset>

.phpstan.dist.neon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
includes:
2+
- phar://phpstan.phar/conf/bleedingEdge.neon
3+
parameters:
4+
phpVersion:
5+
min: 70400
6+
max: 80499
7+
fileExtensions:
8+
- php
9+
paths:
10+
- src
11+
tmpDir: .phpstan.cache
12+
level: 9

.phpunit.dist.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
cacheResultFile=".phpunit.cache/test-results"
6+
executionOrder="depends,defects"
7+
forceCoversAnnotation="true"
8+
beStrictAboutCoversAnnotation="true"
9+
beStrictAboutOutputDuringTests="true"
10+
beStrictAboutTodoAnnotatedTests="true"
11+
convertDeprecationsToExceptions="true"
12+
failOnRisky="true"
13+
failOnWarning="true"
14+
verbose="true">
15+
<testsuites>
16+
<testsuite name="default">
17+
<directory>tests</directory>
18+
</testsuite>
19+
</testsuites>
20+
21+
<coverage cacheDirectory=".phpunit.cache/code-coverage"
22+
processUncoveredFiles="true">
23+
<include>
24+
<directory suffix=".php">src</directory>
25+
</include>
26+
</coverage>
27+
</phpunit>

composer.json

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,38 @@
2626
"symfony/finder": "*"
2727
},
2828
"require-dev": {
29-
"composer/composer": "^2.7",
29+
"composer/composer": "^2.8",
30+
"phpstan/phpstan": "^2.1",
31+
"phpstan/phpstan-strict-rules": "^2.0",
32+
"phpstan/phpstan-symfony": "^2.0",
33+
"phpstan/phpstan-phpunit": "^2.0",
34+
"phpunit/phpunit": "^9.6",
35+
"phpmd/phpmd": "^2.15",
3036
"friendsofphp/php-cs-fixer": "^3.67"
3137
},
3238
"extra": {
3339
"class": "OpenMage\\ComposerPlugin\\Plugin"
3440
},
41+
"scripts": {
42+
"php-cs-fixer:test": "vendor/bin/php-cs-fixer fix --dry-run --diff",
43+
"php-cs-fixer:fix": "vendor/bin/php-cs-fixer fix",
44+
"phpmd": "vendor/bin/phpmd src text .phpmd.dist.xml --color --cache --baseline-file .phpmd.dist.baseline.xml",
45+
"phpstan": "XDEBUG_MODE=off php vendor/bin/phpstan analyze",
46+
"phpstan:baseline": "XDEBUG_MODE=off php vendor/bin/phpstan analyze -b .phpstan.dist.baseline.neon",
47+
"phpunit:test": "XDEBUG_MODE=off php vendor/bin/phpunit --configuration .phpunit.dist.xml --no-coverage",
48+
"phpunit:coverage": "XDEBUG_MODE=coverage php vendor/bin/phpunit --configuration .phpunit.dist.xml --testdox",
49+
"phpunit:coverage-local": "XDEBUG_MODE=coverage php vendor/bin/phpunit --configuration .phpunit.dist.xml --coverage-html build/coverage-composer-plugin --testdox"
50+
},
51+
"scripts-descriptions": {
52+
"php-cs-fixer:test": "Run php-cs-fixer",
53+
"php-cs-fixer:fix": "Run php-cs-fixer and fix issues",
54+
"phpmd": "Run phpmd",
55+
"phpstan": "Run phpstan",
56+
"phpstan:baseline": "Run phpstan and update baseline",
57+
"phpunit:test": "Run PHPUnit",
58+
"phpunit:coverage": "Run PHPUnit with code coverage (requires XDEBUG enabled)",
59+
"phpunit:coverage-local": "Run PHPUnit with local HTML code coverage (requires XDEBUG enabled)"
60+
},
3561
"funding": [
3662
{
3763
"type": "opencollective",

0 commit comments

Comments
 (0)