Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Run CI test

on:
pull_request:
push:
branches:
- main
- develop
- release/**
- hotfix/**
tags:
workflow_dispatch:

jobs:
qa:
name: Full QA / PHP 8.3 / PHPUnit 12
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: xdebug
- run: composer update --prefer-dist --no-interaction
- run: composer validate --strict
- run: composer normalize --dry-run
- run: vendor/bin/grumphp run --no-interaction --tasks=""

phpunit:
name: PHPUnit ${{ matrix.phpunit }} / PHP ${{ matrix.php }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.3', '8.4', '8.5']
phpunit: ['11.5', '12.5']
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
- run: composer update --prefer-dist --no-interaction --with-all-dependencies --with="phpunit/phpunit:^${{ matrix.phpunit }}"
- run: vendor/bin/grumphp run --no-interaction --tasks=phpunit
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/vendor/
/composer.lock
/build/
/.phpunit.result.cache
/*.qa-php.*
/configs/behat.merged.yml
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

All Notable changes to the **Quality Assurance - PHP** package.

## [3.0.0]

### Changed

- Require PHP 8.3 or later.
- Support PHPUnit 11.5 and 12.5 only.
- Refresh the bundled QA tool dependencies and replace Travis CI with GitHub
Actions. PHPCompatibility 9 requires PHPCS 3, which in turn limits Slevomat
to 8.22. PHPCPD 8 and 9 are supported so Composer can select the compatible
`phpunit/php-timer` dependency for PHPUnit 11 or 12.

### Fixed

- Generate a PHPUnit-version-specific `phpunit.qa-php.xml` configuration with
a current XML schema and code-coverage filter.

## [2.2.1]

### Added
Expand Down Expand Up @@ -75,6 +91,7 @@ Initial setup of the qa-php package:
- Add support for PHP 7.3+
- Add support for PHP 8.0+

[3.0.0]: https://github.com/district09/php_package_qa-php/compare/2.2.1...3.0.0
[2.2.1]: https://github.com/district09/php_package_qa-php/compare/2.2.0...2.2.1
[2.2.0]: https://github.com/district09/php_package_qa-php/compare/2.1.0...2.2.0
[2.1.0]: https://github.com/district09/php_package_qa-php/compare/2.0.0...2.1.0
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ Add the `grumphp` entry to the `extra` section of your `composer.json`.
Add the qa-php package as dev requirement:

```bash
composer require --dev district09/qa-php:^2.0
composer require --dev district09/qa-php:^3.0
```

QA PHP 3 requires PHP 8.3 or later and supports PHPUnit 11.5 and 12.5.

## Configuration

### General
Expand Down Expand Up @@ -98,7 +100,11 @@ file:

Running PHPUnit with coverage report is time consuming. You can locally speed up
PHPUnit by copying the generated `phpunit.qa-php.xml` file to
`phpunit.local.xml` and remove the `<coverage>` section from it.
`phpunit.local.xml` and removing the `<coverage>` section from it.

The generated configuration automatically uses the appropriate XML schema for
PHPUnit 11.5 or 12.5. Do not add a project-level `phpunit.xml` only to update
the PHPUnit schema; remove such overrides when upgrading to QA PHP 3.

## Run GrumPHP

Expand Down Expand Up @@ -143,5 +149,5 @@ Configure the paths to these files in PHPStorm:
In order to check php compatibility you can use the phpcs `PHPCompatibility` sniff:

```bash
php vendor/bin/phpcs -p --ignore="*/vendor/*" --extensions=php,inc,module,install,theme --runtime-set testVersion 8.1 --standard=PHPCompatibility ./
php vendor/bin/phpcs -p --ignore="*/vendor/*" --extensions=php,inc,module,install,theme --runtime-set testVersion 8.3 --standard=PHPCompatibility ./
```
66 changes: 38 additions & 28 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"name": "district09/qa-php",
"description": "Quality Assurance tools and configuration for PHP projects and packages.",
"license": "MIT",
"type": "library",
"keywords": [
"district09",
"qa",
"php"
],
"type": "library",
"homepage": "https://github.com/digipolisgent/php_package_qa-php",
"license": "MIT",
"authors": [
{
"name": "Matthijs Van Assche",
Expand All @@ -26,37 +25,48 @@
"role": "developer"
}
],
"homepage": "https://github.com/digipolisgent/php_package_qa-php",
"require": {
"php": "^8.3",
"enlightn/security-checker": "^2.0",
"ergebnis/composer-normalize": "^2.53",
"nette/neon": "^3.4",
"phpcompatibility/php-compatibility": "^9.3.5",
"phpmd/phpmd": "^2.15",
"phpro/grumphp-shim": "^2.23",
"phpspec/prophecy": "^1.26",
"phpspec/prophecy-phpunit": "^2.5",
"phpstan/phpstan": "^2.2",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpunit/phpunit": "^11.5 || ^12.5",
"slevomat/coding-standard": "^8.22",
"squizlabs/php_codesniffer": "^3.13.6",
"symfony/filesystem": "^6.4 || ^7.0",
"systemsdk/phpcpd": "^8.0 || ^9.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true,
"allow-plugins": {
"ergebnis/composer-normalize": true,
"phpro/grumphp-shim": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"autoload": {
"psr-4": {
"District09\\QA\\PHP\\": "src/"
}
},
"require": {
"php": "^8.1",
"enlightn/security-checker": "^1.4|^2.0",
"ergebnis/composer-normalize": "^2.8",
"nette/neon": "^3.2",
"phpcompatibility/php-compatibility": "^9.3",
"phpmd/phpmd": "^2.11",
"phpro/grumphp-shim": "^2.0",
"phpspec/prophecy": "^1.10",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/phpstan": "^1.0 || ^2.0",
"phpstan/phpstan-deprecation-rules": "^1.0 || ^2.0",
"phpunit/phpunit": "^9 || ^10 || ^11 || ^12",
"slevomat/coding-standard": "^8.15",
"squizlabs/php_codesniffer": "^3.5.6",
"symfony/filesystem": "^5.2|^6.0|^7.0",
"systemsdk/phpcpd": "^7.0 || ^8.0"
"autoload-dev": {
"psr-4": {
"District09\\QA\\PHP\\Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"ergebnis/composer-normalize": true,
"phpro/grumphp-shim": true
},
"sort-packages": true
},
"extra": {
"grumphp": {
"config-default-path": "configs/grumphp.yml"
}
}
}
1 change: 1 addition & 0 deletions configs/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ parameters:
scanDirectories:
- %currentWorkingDirectory%/src
- %currentWorkingDirectory%/tests
- %currentWorkingDirectory%/stubs
27 changes: 27 additions & 0 deletions configs/phpunit-11.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"
bootstrap="vendor/autoload.php"
colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory suffix="Interface.php">src</directory>
</exclude>
</source>
<coverage includeUncoveredFiles="true">
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
</report>
</coverage>
<testsuites>
<testsuite name="District09 QA PHP">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
13 changes: 7 additions & 6 deletions configs/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
colors="true"
verbose="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.5/phpunit.xsd"
>
<coverage processUncoveredFiles="true">
<source>
<include>
<directory suffix=".php">src/</directory>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory suffix="Interface.php">src/</directory>
<directory suffix="Interface.php">src</directory>
</exclude>
</source>
<coverage includeUncoveredFiles="true">
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
</report>
</coverage>

<testsuites>
<testsuite name="District09/gent-lez">
<testsuite name="District09 QA PHP">
<directory>tests</directory>
</testsuite>
</testsuites>
Expand Down
36 changes: 27 additions & 9 deletions src/GrumPHP/EventListener/TaskEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

namespace District09\QA\PHP\GrumPHP\EventListener;

use District09\QA\PHP\GrumPHP\PhpunitConfigResolver;
use GrumPHP\Event\TaskEvent;
use GrumPHP\Task\Phpcs;
use GrumPHP\Task\PhpMd;
use GrumPHP\Task\PhpStan;
use GrumPHP\Task\Phpunit;
use GrumPHP\Task\TaskInterface;
use Nette\Neon\Neon;
use PHPUnit\Runner\Version;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Yaml\Yaml;

Expand Down Expand Up @@ -65,6 +67,8 @@ final class TaskEventListener
*
* @param TaskEvent $event
* The GrumPHP task event.
*
* @SuppressWarnings("PHPMD.Superglobals")
*/
public function createTaskConfig(TaskEvent $event): void
{
Expand Down Expand Up @@ -98,21 +102,16 @@ public function createTaskConfig(TaskEvent $event): void
$info['filename'],
$info['extension']
),
$keyPrefix . 'GLOBAL' => sprintf(
'%s%s.%s',
$packagePath,
$info['filename'],
$info['extension']
),
$keyPrefix . 'GLOBAL' => $this->getGlobalConfigFile($info, $packagePath),
];

// Search for the candidates and merge or copy them.
$filesystem = new Filesystem();
$dataMerged = [];

foreach ($candidates as $env_var => $file) {
foreach ($candidates as $envVar => $file) {
// Ignore if configured to skip or if the file is missing.
if (!empty($_SERVER[$env_var]) || !$filesystem->exists($file)) {
if (!empty($GLOBALS['_SERVER'][$envVar]) || !$filesystem->exists($file)) {
continue;
}

Expand Down Expand Up @@ -159,6 +158,25 @@ private function getTaskConfigFileInfo(TaskInterface $task): ?array
return $info;
}

/**
* Gets the global configuration file for a GrumPHP task.
*
* @param array $info
* The task configuration information.
* @param string $packagePath
* The bundled configuration directory.
*/
private function getGlobalConfigFile(array $info, string $packagePath): string
{
if ($info['filename'] === 'phpunit') {
$filename = PhpunitConfigResolver::resolve(Version::majorVersionNumber());

return $packagePath . $filename;
}

return sprintf('%s%s.%s', $packagePath, $info['filename'], $info['extension']);
}

/**
* Read and parse a task configuration file.
*
Expand Down Expand Up @@ -190,7 +208,7 @@ private function readTaskConfigFile(string $type, string $file): array|bool
* The file type.
* @param string $file
* Path to the file.
* @param array|null $data
* @param array $data
* The configuration data.
*/
private function writeTaskConfigFile(string $type, string $file, array $data): void
Expand Down
Loading
Loading