Skip to content

Refresh PHPUnit setup #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2025
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
24 changes: 16 additions & 8 deletions .github/workflows/testing-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@ jobs:
PHP:
strategy:
matrix:
image: [
'srcoder/development-php:php74-fpm',
'srcoder/development-php:php80-fpm',
'srcoder/development-php:php81-fpm'
]
php-version: [8.1, 8.2, 8.3, 8.4]
runs-on: ubuntu-latest
container:
image: ${{ matrix.image }}
image: ${{ matrix.php-version == '8.1' && 'srcoder/development-php:php81-fpm' ||
matrix.php-version == '8.2' && 'srcoder/development-php:php82-fpm' ||
matrix.php-version == '8.3' && 'srcoder/development-php:php83-fpm' ||
matrix.php-version == '8.4' && 'srcoder/development-php:php84-fpm' }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Testing Suite

- name: Install Dependencies
run: |
composer2 install --dev --prefer-dist --no-scripts --no-progress --optimize-autoloader --no-interaction -vvv
composer2 show
composer2 exec -v grumphp run
shell: bash

- name: Run GrumPHP Tasks
run: |
if [[ "${{ matrix.php-version }}" == "8.1" || "${{ matrix.php-version }}" == "8.2" ]]; then
composer2 exec -v grumphp -- run --tasks=composer,jsonlint,xmllint,yamllint,phpcs,phplint,phpmd,phpstan,securitychecker_enlightn
else
composer2 exec -v grumphp -- run
fi
shell: bash
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.0.0] - Unreleased
### Added
- Added `phpunit/phpunit` to suggested dependencies in `composer.json`.
- Added `youwe/coding-standard-phpstorm` to suggested dependencies in `composer.json`.
- Added support to honor upstream version constraints
- Github action for php 8.3 and php 8.4 to run unit tests against PHPUnit 12.
- Testing suite now attempts to install phpunit upstream if it isn't available yet
- Existing upstream versions are honored if already installed
- Upstream projects not having phpunit installed will install phpunit with an @stable version

### Changed
- Unit tests as part of the testing suite are rewritten for PHPUnit 12
- Updated GitHub Action workflows to support PHP 8.1, 8.2, and 8.3.
- `composer.json`: Dropped support for PHP < 8.1.
- Moved phpunit from require to require-dev
- 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.

### Removed
- Removed support for EOL PHP versions. Projects running PHP < 8.1 can stick to version 2 of the testing-suite.
- Removed support for Composer 1. Projects still relying on Composer 1 can stick to version 2 of the testing-suite.
- Removed `youwe/coding-standard-phpstorm` as dependency (it is still listed in suggest)
- Removed `phpunit/phpunit` as direct dependency (it is still in require-dev and installed upstream through the `youwe/dependency-installer`)
- Github actions for php < 8.1

## 2.19.1
### Changed
- `^0.30` restricts updates to only versions within the `0.30.x` range, preventing upgrades to 0.32.0 for
Expand Down
12 changes: 10 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Before opening a PR with changes, make sure all the linting steps are successful.

The require-dev dependency for phpunit is set to @stable for the github actions, but the tests themselves\
assume they are running against PHPUnit 12 and php >= 8.3. The github actions only run phpunit tests against\
a php 8.3 container.

If a PR is approved please ask one of the following maintainers to get it merged:
[Igor Wulff](https://github.com/igorwulff)
[Dan Wallis](https://github.com/fredden)

- [Igor Wulff](https://github.com/igorwulff)
- [Leon Helmus](https://github.com/leonhelmus)
- [Rutger Rademakers](https://github.com/rutgerrademaker)
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,25 @@
}
],
"require": {
"php": "^7.2 || ^8.0",
"composer-plugin-api": "^1.1 || ^2.0",
"php": "^8.1",
"composer-plugin-api": "^2.0",
"enlightn/security-checker": "^1.5 || ^2.0",
"kint-php/kint": "@stable",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpro/grumphp-shim": "^1.13",
"phpstan/phpstan": "@stable",
"phpunit/phpunit": "@stable",
"youwe/coding-standard": "^3.5.0",
"youwe/coding-standard-phpstorm": "^2.3.0",
"youwe/composer-dependency-installer": "^1.4.0",
"youwe/composer-file-installer": "^1.2.0"
},
"suggest": {
"phpunit/phpunit": ">= 9.6",
"youwe/coding-standard-phpstorm": "^2.3.0"
},
"require-dev": {
"composer/composer": "@stable",
"mikey179/vfsstream": "@stable"
"mikey179/vfsstream": "@stable",
"phpunit/phpunit": "@stable"
},
"replace": {
"sensiolabs/security-checker": "*"
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
parameters:
excludePaths:
- src/installers.php
- tests/*
ignoreErrors:
- '#Property Mediact\\TestingSuite\\Composer\\Installer\\ConfigInstaller::\$io is never read, only written\.#'
4 changes: 2 additions & 2 deletions src/ConfigResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class ConfigResolver
* Constructor.
*
* @param ProjectTypeResolver $typeResolver
* @param string $template
* @param string|null $template
*/
public function __construct(
ProjectTypeResolver $typeResolver,
string $template = null
?string $template = null,
) {
$this->typeResolver = $typeResolver;
$this->template = $template ?? $this->template;
Expand Down
1 change: 1 addition & 0 deletions src/Factory/ProcessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ProcessFactory implements ProcessFactoryInterface
public function create(string $commandLine): Process
{
// See https://github.com/composer/composer/blob/1.10.17/src/Composer/Util/ProcessExecutor.php#L68:L72
// @phpstan-ignore-next-line because phpstan can see it's available, but we cannot guarantee symfony >= 4.2 upstream
return method_exists(Process::class, 'fromShellCommandline')
? Process::fromShellCommandline($commandLine) // Symfony >= 4.2
: new Process($commandLine); // Symfony < 4.2
Expand Down
20 changes: 11 additions & 9 deletions src/Installer/ArchiveExcludeInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
use Composer\Factory;
use Composer\IO\IOInterface;
use Composer\Json\JsonFile;
use Exception;
use Youwe\FileMapping\FileMappingInterface;
use Youwe\TestingSuite\Composer\MappingResolver;

/**
* @SuppressWarnings(PHPMD.ShortVariable)
* @SuppressWarnings(PHPMD.StaticAccess)
* @SuppressWarnings("PHPMD.ShortVariable")
* @SuppressWarnings("PHPMD.StaticAccess")
*/
class ArchiveExcludeInstaller implements InstallerInterface
{
Expand All @@ -41,7 +42,7 @@ class ArchiveExcludeInstaller implements InstallerInterface
'/.env.dev',
'/.gitattributes',
'/.gitignore',
'/tests'
'/tests',
];

/**
Expand All @@ -50,15 +51,15 @@ class ArchiveExcludeInstaller implements InstallerInterface
* @param MappingResolver $resolver
* @param IOInterface $io
* @param JsonFile|null $file
* @param string $destination
* @param string |null $destination
* @param array|null $defaults
*/
public function __construct(
MappingResolver $resolver,
IOInterface $io,
JsonFile $file = null,
string $destination = null,
array $defaults = null
?JsonFile $file = null,
?string $destination = null,
?array $defaults = null,
) {
$this->resolver = $resolver;
$this->io = $io;
Expand All @@ -71,6 +72,7 @@ public function __construct(
* Install.
*
* @return void
* @throws Exception
*/
public function install(): void
{
Expand All @@ -94,7 +96,7 @@ function (FileMappingInterface $mapping): string {
},
iterator_to_array(
$this->resolver->resolve()
)
),
)
);

Expand All @@ -107,7 +109,7 @@ function (FileMappingInterface $mapping): string {
$this->io->write(
sprintf(
'<info>Added:</info> %s to archive exclude in composer.json',
$file
$file,
)
);
}
Expand Down
11 changes: 6 additions & 5 deletions src/Installer/ConfigInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
namespace Youwe\TestingSuite\Composer\Installer;

use Composer\Factory;
use Composer\IO\IOInterface;
use Composer\Json\JsonFile;
use Seld\JsonLint\ParsingException;
use Youwe\TestingSuite\Composer\ConfigResolver;

/**
* @SuppressWarnings(PHPMD.ShortVariable)
* @SuppressWarnings(PHPMD.StaticAccess)
* @SuppressWarnings("PHPMD.ShortVariable")
* @SuppressWarnings("PHPMD.StaticAccess")
*/
class ConfigInstaller implements InstallerInterface
{
Expand All @@ -34,7 +34,7 @@ class ConfigInstaller implements InstallerInterface
*/
public function __construct(
ConfigResolver $resolver,
JsonFile $file = null
?JsonFile $file = null,
) {
$this->resolver = $resolver;
$this->file = $file ?? new JsonFile(Factory::getComposerFile());
Expand All @@ -44,6 +44,7 @@ public function __construct(
* Install.
*
* @return void
* @throws ParsingException
*/
public function install(): void
{
Expand All @@ -52,7 +53,7 @@ public function install(): void

$config = array_replace_recursive(
$this->resolver->resolve(),
$config
$config,
);

$definition['config'] = $config;
Expand Down
46 changes: 26 additions & 20 deletions src/Installer/FilesInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Youwe\TestingSuite\Composer\MappingResolver;

/**
* @SuppressWarnings(PHPMD.ShortVariable)
* @SuppressWarnings("PHPMD.ShortVariable")
*/
class FilesInstaller implements InstallerInterface
{
Expand All @@ -38,7 +38,7 @@ class FilesInstaller implements InstallerInterface
public function __construct(
MappingResolver $mappingResolver,
ComposerFileInstaller $fileInstaller,
IOInterface $io
IOInterface $io,
) {
$this->mappingResolver = $mappingResolver;
$this->fileInstaller = $fileInstaller;
Expand All @@ -63,7 +63,7 @@ public function install(): void
$this->io->write(
sprintf(
'<info>Installed:</info> %s',
$mapping->getRelativeDestination()
$mapping->getRelativeDestination(),
)
);
}
Expand All @@ -72,7 +72,7 @@ public function install(): void
/**
* @param FileMappingInterface $unixFileMapping
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings("PHPMD.CyclomaticComplexity")
*
* @return void
*/
Expand All @@ -87,59 +87,65 @@ private function resolveYouwePathing(FileMappingInterface $unixFileMapping): voi
[
'./vendor/mediact/coding-standard-magento2/src/MediactMagento2',
'./vendor/mediact/coding-standard/src/MediaCT',
'./vendor/youwe/coding-standard-magento2/src/Magento2'
'./vendor/youwe/coding-standard-magento2/src/Magento2',
],
'YouweMagento2'
'YouweMagento2',
);
} elseif ($name === "phpmd.xml") {
$this->updatePath(
$unixFileMapping->getDestination(),
[
'./vendor/mediact/coding-standard-magento2/src/MediactMagento2/phpmd.xml',
'./vendor/mediact/coding-standard/src/MediaCT/phpmd.xml',
'./vendor/youwe/coding-standard-magento2/src/Magento2/phpmd.xml'
'./vendor/youwe/coding-standard-magento2/src/Magento2/phpmd.xml',
],
'./vendor/youwe/coding-standard-magento2/src/YouweMagento2/phpmd.xml'
'./vendor/youwe/coding-standard-magento2/src/YouweMagento2/phpmd.xml',
);
} elseif ($name === "grumphp.yml") {
$this->updatePath(
$unixFileMapping->getDestination(),
[
'vendor/mediact/testing-suite/config/default/grumphp.yml',
'vendor/youwe/testing-suite/config/default/grumphp.yml'
'vendor/youwe/testing-suite/config/default/grumphp.yml',
],
'vendor/youwe/testing-suite/config/magento2/grumphp.yml'
'vendor/youwe/testing-suite/config/magento2/grumphp.yml',
);
}
} elseif ($this->mappingResolver->getTypeResolver()->resolve() === 'magento') {
if ($name === "phpcs.xml") {
$this->updatePath(
$unixFileMapping->getDestination(),
['./vendor/mediact/coding-standard-magento1/src/MediactMagento1'],
'./vendor/youwe/coding-standard-magento1/src/Magento1'
[
'./vendor/mediact/coding-standard-magento1/src/MediactMagento1',
],
'./vendor/youwe/coding-standard-magento1/src/Magento1',
);
}
} else {
if ($name === "phpcs.xml") {
$this->updatePath(
$unixFileMapping->getDestination(),
['./vendor/mediact/coding-standard/src/MediaCT'],
'./vendor/youwe/coding-standard/src/Global'
[
'./vendor/mediact/coding-standard/src/MediaCT',
],
'./vendor/youwe/coding-standard/src/Global',
);
} elseif ($name === "phpmd.xml") {
$this->updatePath(
$unixFileMapping->getDestination(),
[
'./vendor/mediact/coding-standard/src/MediaCT/phpmd.xml',
'./vendor/youwe/coding-standard-magento2/src/Magento2/phpmd.xml'
'./vendor/youwe/coding-standard-magento2/src/Magento2/phpmd.xml',
],
'./vendor/youwe/coding-standard/src/Global/phpmd.xml'
'./vendor/youwe/coding-standard/src/Global/phpmd.xml',
);
} elseif ($name === "grumphp.yml") {
$this->updatePath(
$unixFileMapping->getDestination(),
['vendor/mediact/testing-suite/config/default/grumphp.yml'],
'vendor/youwe/testing-suite/config/default/grumphp.yml'
[
'vendor/mediact/testing-suite/config/default/grumphp.yml',
],
'vendor/youwe/testing-suite/config/default/grumphp.yml',
);
}
}
Expand All @@ -155,13 +161,13 @@ private function resolveYouwePathing(FileMappingInterface $unixFileMapping): voi
private function updatePath(
string $destination,
array $oldPaths,
string $newPath
string $newPath,
): void {
$file = file_get_contents($destination);
$newFile = str_replace(
$oldPaths,
$newPath,
$file
$file,
);
file_put_contents($destination, $newFile);
}
Expand Down
Loading