Skip to content

Commit

Permalink
V4: refactor, tests, workflow (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel authored Jan 13, 2025
1 parent 43fcc0a commit 4304691
Show file tree
Hide file tree
Showing 30 changed files with 1,320 additions and 117 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/phpmd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: PHPMD

on: [push, pull_request]

jobs:
phpcs:
name: Mess Detector
runs-on: [ubuntu-latest]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-*

- name: PHPMD
run: php vendor/bin/phpmd src/ github .phpmd.dist.xml --baseline-file .phpmd.dist.baseline.xml
48 changes: 48 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: PHPStan

on: [push, pull_request]

jobs:
phpstan:
name: Analyze
runs-on: [ubuntu-latest]

steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4

- uses: actions/checkout@v4

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-*

- name: Restore result cache
uses: actions/cache/restore@v4
with:
path: .phpstan.cache
key: phpstan-result-cache-${{ github.run_id }}
restore-keys: |
phpstan-result-cache-
- name: PHPStan Static Analysis
run: XDEBUG_MODE=off php vendor/bin/phpstan.phar analyze

- name: Save result cache
uses: actions/cache/save@v4
if: always()
with:
path: .phpstan.cache
key: phpstan-result-cache-${{ github.run_id }}
39 changes: 39 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: PHPUnit

on: [push, pull_request]

jobs:
unit-tests:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.4', '8.3']

steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: pcov #optional, setup coverage driver
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/checkout@v4

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-*

- name: Run phpUnit
run: php vendor/bin/phpunit --configuration .phpunit.dist.xml
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/.idea
/vendor
/.phpstan.cache
/.phpunit.cache
.php-cs-fixer.cache
.phpmd.result-cache.php
composer.lock
7 changes: 7 additions & 0 deletions .phpmd.dist.baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<phpmd-baseline>
<violation rule="PHPMD\Rule\Design\WeightedMethodCount" file="src/OpenMage/ComposerPlugin/Copy/AbstractCopyPlugin.php"/>
<violation rule="PHPMD\Rule\CyclomaticComplexity" file="src/OpenMage/ComposerPlugin/Copy/AbstractCopyPlugin.php" method="processComposerInstall"/>
<violation rule="PHPMD\Rule\CyclomaticComplexity" file="src/OpenMage/ComposerPlugin/Copy/AbstractCopyPlugin.php" method="processUnpkgInstall"/>
<violation rule="PHPMD\Rule\Design\NpathComplexity" file="src/OpenMage/ComposerPlugin/Copy/AbstractCopyPlugin.php" method="processUnpkgInstall"/>
</phpmd-baseline>
23 changes: 23 additions & 0 deletions .phpmd.dist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<ruleset name="OpenMage ruleset"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 https://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="https://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
OpenMage ruleset
</description>
<rule ref="rulesets/unusedcode.xml" />
<rule ref="rulesets/cleancode.xml" />
<rule ref="rulesets/controversial.xml" />
<rule ref="rulesets/naming.xml">
<exclude name="ShortVariable" />
</rule>
<rule ref="rulesets/naming.xml/ShortVariable">
<properties>
<property name="exceptions" value="io" />
</properties>
</rule>
<rule ref="rulesets/design.xml" />
<rule ref="rulesets/codesize.xml" />
</ruleset>
12 changes: 12 additions & 0 deletions .phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
includes:
- phar://phpstan.phar/conf/bleedingEdge.neon
parameters:
phpVersion:
min: 70400
max: 80499
fileExtensions:
- php
paths:
- src
tmpDir: .phpstan.cache
level: 9
27 changes: 27 additions & 0 deletions .phpunit.dist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
28 changes: 27 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,38 @@
"symfony/finder": "*"
},
"require-dev": {
"composer/composer": "^2.7",
"composer/composer": "^2.8",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-strict-rules": "^2.0",
"phpstan/phpstan-symfony": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^9.6",
"phpmd/phpmd": "^2.15",
"friendsofphp/php-cs-fixer": "^3.67"
},
"extra": {
"class": "OpenMage\\ComposerPlugin\\Plugin"
},
"scripts": {
"php-cs-fixer:test": "vendor/bin/php-cs-fixer fix --dry-run --diff",
"php-cs-fixer:fix": "vendor/bin/php-cs-fixer fix",
"phpmd": "vendor/bin/phpmd src text .phpmd.dist.xml --color --cache --baseline-file .phpmd.dist.baseline.xml",
"phpstan": "XDEBUG_MODE=off php vendor/bin/phpstan analyze",
"phpstan:baseline": "XDEBUG_MODE=off php vendor/bin/phpstan analyze -b .phpstan.dist.baseline.neon",
"phpunit:test": "XDEBUG_MODE=off php vendor/bin/phpunit --configuration .phpunit.dist.xml --no-coverage",
"phpunit:coverage": "XDEBUG_MODE=coverage php vendor/bin/phpunit --configuration .phpunit.dist.xml --testdox",
"phpunit:coverage-local": "XDEBUG_MODE=coverage php vendor/bin/phpunit --configuration .phpunit.dist.xml --coverage-html build/coverage-composer-plugin --testdox"
},
"scripts-descriptions": {
"php-cs-fixer:test": "Run php-cs-fixer",
"php-cs-fixer:fix": "Run php-cs-fixer and fix issues",
"phpmd": "Run phpmd",
"phpstan": "Run phpstan",
"phpstan:baseline": "Run phpstan and update baseline",
"phpunit:test": "Run PHPUnit",
"phpunit:coverage": "Run PHPUnit with code coverage (requires XDEBUG enabled)",
"phpunit:coverage-local": "Run PHPUnit with local HTML code coverage (requires XDEBUG enabled)"
},
"funding": [
{
"type": "opencollective",
Expand Down
Loading

0 comments on commit 4304691

Please sign in to comment.