Skip to content

Commit d0ae02f

Browse files
author
Stefan Boonstra
committed
WIP
1 parent 8c38b9a commit d0ae02f

11 files changed

+131
-84
lines changed

.github/workflows/testing-suite.yml

+14-19
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,28 @@ jobs:
44
PHP:
55
strategy:
66
matrix:
7-
image: [
8-
'srcoder/development-php:php81-fpm',
9-
'srcoder/development-php:php82-fpm'
10-
]
7+
php-version: [8.1, 8.2, 8.3, 8.4]
118
runs-on: ubuntu-latest
129
container:
13-
image: ${{ matrix.image }}
10+
image: ${{ matrix.php-version == '8.1' && 'srcoder/development-php:php81-fpm' ||
11+
matrix.php-version == '8.2' && 'srcoder/development-php:php82-fpm' ||
12+
matrix.php-version == '8.3' && 'srcoder/development-php:php83-fpm' ||
13+
matrix.php-version == '8.4' && 'srcoder/development-php:php84-fpm' }}
1414
steps:
1515
- name: Checkout
1616
uses: actions/checkout@v2
17-
- name: Testing Suite
18-
# We are purposefully skipping the phpunit task since it is written for phpunit ^12 and php >= 8.3
17+
18+
- name: Install Dependencies
1919
run: |
2020
composer2 install --dev --prefer-dist --no-scripts --no-progress --optimize-autoloader --no-interaction -vvv
2121
composer2 show
22-
composer2 exec -v grumphp -- run --tasks=composer,jsonlint,xmllint,yamllint,phpcs,phplint,phpmd,phpstan,securitychecker_enlightn
2322
shell: bash
24-
PHPWithUnitTests:
25-
runs-on: ubuntu-latest
26-
container:
27-
image: 'srcoder/development-php:php83-fpm'
28-
steps:
29-
- name: Checkout
30-
uses: actions/checkout@v2
31-
- name: Testing Suite
23+
24+
- name: Run GrumPHP Tasks
3225
run: |
33-
composer2 install --dev --prefer-dist --no-scripts --no-progress --optimize-autoloader --no-interaction -vvv
34-
composer2 show
35-
composer2 exec -v grumphp -- run --tasks=composer,jsonlint,xmllint,yamllint,phpcs,phplint,phpmd,phpstan,phpunit,securitychecker_enlightn
26+
if [[ "${{ matrix.php-version }}" == "8.1" || "${{ matrix.php-version }}" == "8.2" ]]; then
27+
composer2 exec -v grumphp -- run --tasks=composer,jsonlint,xmllint,yamllint,phpcs,phplint,phpmd,phpstan,securitychecker_enlightn
28+
else
29+
composer2 exec -v grumphp -- run
30+
fi
3631
shell: bash

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
],
2626
"require": {
2727
"php": "^8.1",
28-
"composer-plugin-api": "^1.1 || ^2.0",
28+
"composer-plugin-api": "^2.0",
2929
"enlightn/security-checker": "^1.5 || ^2.0",
3030
"kint-php/kint": "@stable",
3131
"php-parallel-lint/php-parallel-lint": "^1.2",
@@ -36,7 +36,7 @@
3636
"youwe/composer-file-installer": "^1.2.0"
3737
},
3838
"suggest": {
39-
"phpunit/phpunit": "^9.6 || ^10.5 || ^11.5 || ^12.0",
39+
"phpunit/phpunit": ">= 9.6",
4040
"youwe/coding-standard-phpstorm": "^2.3.0"
4141
},
4242
"require-dev": {

src/ConfigResolver.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ class ConfigResolver
2121
* Constructor.
2222
*
2323
* @param ProjectTypeResolver $typeResolver
24-
* @param string $template
24+
* @param string|null $template
2525
*/
2626
public function __construct(
2727
ProjectTypeResolver $typeResolver,
28-
string $template = null
28+
?string $template = null
2929
) {
3030
$this->typeResolver = $typeResolver;
3131
$this->template = $template ?? $this->template;

src/Installer/ArchiveExcludeInstaller.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Composer\Factory;
1313
use Composer\IO\IOInterface;
1414
use Composer\Json\JsonFile;
15+
use Exception;
16+
use Seld\JsonLint\ParsingException;
1517
use Youwe\FileMapping\FileMappingInterface;
1618
use Youwe\TestingSuite\Composer\MappingResolver;
1719

@@ -41,7 +43,7 @@ class ArchiveExcludeInstaller implements InstallerInterface
4143
'/.env.dev',
4244
'/.gitattributes',
4345
'/.gitignore',
44-
'/tests'
46+
'/tests',
4547
];
4648

4749
/**
@@ -50,15 +52,15 @@ class ArchiveExcludeInstaller implements InstallerInterface
5052
* @param MappingResolver $resolver
5153
* @param IOInterface $io
5254
* @param JsonFile|null $file
53-
* @param string $destination
55+
* @param string |null $destination
5456
* @param array|null $defaults
5557
*/
5658
public function __construct(
5759
MappingResolver $resolver,
5860
IOInterface $io,
59-
JsonFile $file = null,
60-
string $destination = null,
61-
array $defaults = null
61+
?JsonFile $file = null,
62+
?string $destination = null,
63+
?array $defaults = null
6264
) {
6365
$this->resolver = $resolver;
6466
$this->io = $io;
@@ -71,6 +73,7 @@ public function __construct(
7173
* Install.
7274
*
7375
* @return void
76+
* @throws Exception
7477
*/
7578
public function install(): void
7679
{

src/Installer/ConfigInstaller.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ConfigInstaller implements InstallerInterface
3434
*/
3535
public function __construct(
3636
ConfigResolver $resolver,
37-
JsonFile $file = null
37+
?JsonFile $file = null
3838
) {
3939
$this->resolver = $resolver;
4040
$this->file = $file ?? new JsonFile(Factory::getComposerFile());

src/Installer/FilesInstaller.php

+13-7
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private function resolveYouwePathing(FileMappingInterface $unixFileMapping): voi
8787
[
8888
'./vendor/mediact/coding-standard-magento2/src/MediactMagento2',
8989
'./vendor/mediact/coding-standard/src/MediaCT',
90-
'./vendor/youwe/coding-standard-magento2/src/Magento2'
90+
'./vendor/youwe/coding-standard-magento2/src/Magento2',
9191
],
9292
'YouweMagento2'
9393
);
@@ -97,7 +97,7 @@ private function resolveYouwePathing(FileMappingInterface $unixFileMapping): voi
9797
[
9898
'./vendor/mediact/coding-standard-magento2/src/MediactMagento2/phpmd.xml',
9999
'./vendor/mediact/coding-standard/src/MediaCT/phpmd.xml',
100-
'./vendor/youwe/coding-standard-magento2/src/Magento2/phpmd.xml'
100+
'./vendor/youwe/coding-standard-magento2/src/Magento2/phpmd.xml',
101101
],
102102
'./vendor/youwe/coding-standard-magento2/src/YouweMagento2/phpmd.xml'
103103
);
@@ -106,7 +106,7 @@ private function resolveYouwePathing(FileMappingInterface $unixFileMapping): voi
106106
$unixFileMapping->getDestination(),
107107
[
108108
'vendor/mediact/testing-suite/config/default/grumphp.yml',
109-
'vendor/youwe/testing-suite/config/default/grumphp.yml'
109+
'vendor/youwe/testing-suite/config/default/grumphp.yml',
110110
],
111111
'vendor/youwe/testing-suite/config/magento2/grumphp.yml'
112112
);
@@ -115,30 +115,36 @@ private function resolveYouwePathing(FileMappingInterface $unixFileMapping): voi
115115
if ($name === "phpcs.xml") {
116116
$this->updatePath(
117117
$unixFileMapping->getDestination(),
118-
['./vendor/mediact/coding-standard-magento1/src/MediactMagento1'],
118+
[
119+
'./vendor/mediact/coding-standard-magento1/src/MediactMagento1',
120+
],
119121
'./vendor/youwe/coding-standard-magento1/src/Magento1'
120122
);
121123
}
122124
} else {
123125
if ($name === "phpcs.xml") {
124126
$this->updatePath(
125127
$unixFileMapping->getDestination(),
126-
['./vendor/mediact/coding-standard/src/MediaCT'],
128+
[
129+
'./vendor/mediact/coding-standard/src/MediaCT',
130+
],
127131
'./vendor/youwe/coding-standard/src/Global'
128132
);
129133
} elseif ($name === "phpmd.xml") {
130134
$this->updatePath(
131135
$unixFileMapping->getDestination(),
132136
[
133137
'./vendor/mediact/coding-standard/src/MediaCT/phpmd.xml',
134-
'./vendor/youwe/coding-standard-magento2/src/Magento2/phpmd.xml'
138+
'./vendor/youwe/coding-standard-magento2/src/Magento2/phpmd.xml',
135139
],
136140
'./vendor/youwe/coding-standard/src/Global/phpmd.xml'
137141
);
138142
} elseif ($name === "grumphp.yml") {
139143
$this->updatePath(
140144
$unixFileMapping->getDestination(),
141-
['vendor/mediact/testing-suite/config/default/grumphp.yml'],
145+
[
146+
'vendor/mediact/testing-suite/config/default/grumphp.yml',
147+
],
142148
'vendor/youwe/testing-suite/config/default/grumphp.yml'
143149
);
144150
}

src/Installer/PackagesInstaller.php

+24-34
Original file line numberDiff line numberDiff line change
@@ -35,47 +35,36 @@ class PackagesInstaller implements InstallerInterface
3535
/** @var array */
3636
public $mapping = [
3737
MappingResolver::DEFAULT_MAPPING_TYPE => [
38-
[
39-
'name' => 'phpunit/phpunit',
38+
'phpunit/phpunit' => [
4039
'version' => '@stable',
41-
'dev' => true,
42-
'allowVersionOverride' => false
40+
'updateDependencies' => true,
41+
'allowVersionOverride' => false,
4342
]
4443
],
4544
'magento1' => [
46-
[
47-
'name' => 'youwe/coding-standard-magento1',
45+
'youwe/coding-standard-magento1' => [
4846
'version' => '^1.3.0',
49-
'dev' => true,
50-
'allowVersionOverride' => true
47+
'updateDependencies' => true,
5148
]
5249
],
5350
'magento2' => [
54-
[
55-
'name' => 'youwe/coding-standard-magento2',
51+
'youwe/coding-standard-magento2' => [
5652
'version' => '^2.0.0',
57-
'dev' => true,
58-
'allowVersionOverride' => true
53+
'updateDependencies' => true,
5954
],
60-
[
61-
'name' => 'phpstan/extension-installer',
55+
'phpstan/extension-installer' => [
6256
'version' => '^1.3',
63-
'dev' => true,
64-
'allowVersionOverride' => true,
57+
'updateDependencies' => true,
6558
],
66-
[
67-
'name' => 'bitexpert/phpstan-magento',
59+
'bitexpert/phpstan-magento' => [
6860
'version' => '~0.30',
69-
'dev' => true,
70-
'allowVersionOverride' => true,
61+
'updateDependencies' => true,
7162
],
7263
],
7364
'laravel' => [
74-
[
75-
'name' => 'elgentos/laravel-coding-standard',
65+
'elgentos/laravel-coding-standard' => [
7666
'version' => '^1.0.0',
77-
'dev' => true,
78-
'allowVersionOverride' => true,
67+
'updateDependencies' => true,
7968
]
8069
]
8170
];
@@ -93,8 +82,8 @@ public function __construct(
9382
Composer $composer,
9483
ProjectTypeResolver $typeResolver,
9584
IOInterface $io,
96-
DependencyInstaller $installer = null,
97-
array $mapping = null
85+
?DependencyInstaller $installer = null,
86+
?array $mapping = null
9887
) {
9988
$this->composer = $composer;
10089
$this->typeResolver = $typeResolver;
@@ -112,20 +101,20 @@ public function install(): void
112101
{
113102
$type = $this->typeResolver->resolve();
114103
$projectTypePackages = $this->mapping[$type] ?? [];
115-
$packagesToInstall = array_merge($projectTypePackages, $this->mapping[MappingResolver::DEFAULT_MAPPING_TYPE]);
104+
$packagesToInstall = array_replace_recursive($this->mapping[MappingResolver::DEFAULT_MAPPING_TYPE], $projectTypePackages);
116105

117-
foreach ($packagesToInstall as $package) {
118-
if (!$this->isPackageRequired($package['name'], $package['version'])) {
106+
foreach ($packagesToInstall as $name => $package) {
107+
if (!$this->isPackageRequired($name, $package['version'])) {
119108
$this->io->write(
120-
sprintf('Requiring package %s', $package['name'])
109+
sprintf('Requiring package %s', $name)
121110
);
122111

123112
$this->installer->installPackage(
124-
$package['name'],
113+
$name,
125114
$package['version'],
126-
true,
127-
false,
128-
$package['allowVersionOverride']
115+
$package['dev'] ?? true,
116+
$package['updateDependencies'] ?? false,
117+
$package['allowVersionOverride'] ?? true
129118
);
130119
}
131120
}
@@ -135,6 +124,7 @@ public function install(): void
135124
* Whether a package has been required.
136125
*
137126
* @param string $packageName
127+
* @param string $version
138128
*
139129
* @return bool
140130
*/

src/Plugin.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ public static function getSubscribedEvents(): array
105105
{
106106
return [
107107
'post-install-cmd' => [
108-
'install'
108+
'install',
109109
],
110110
'post-update-cmd' => [
111-
'install'
112-
]
111+
'install',
112+
],
113113
];
114114
}
115115
}

src/ProjectTypeResolver.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ProjectTypeResolver
2121
*/
2222
public const COMPOSER_CONFIG_KEYS = [
2323
'youwe-testing-suite',
24-
'mediact-testing-suite'
24+
'mediact-testing-suite',
2525
];
2626

2727
/**
@@ -40,7 +40,7 @@ class ProjectTypeResolver
4040
'magento-project' => 'magento2',
4141
'alumio-project' => 'alumio',
4242
'laravel-project' => 'laravel',
43-
'pimcore-project' => 'pimcore'
43+
'pimcore-project' => 'pimcore',
4444
];
4545

4646
public const DEFAULT_PROJECT_TYPE = 'default';
@@ -51,7 +51,7 @@ class ProjectTypeResolver
5151
* @param Composer $composer
5252
* @param array|null $mapping
5353
*/
54-
public function __construct(Composer $composer, array $mapping = null)
54+
public function __construct(Composer $composer, ?array $mapping = null)
5555
{
5656
$this->composer = $composer;
5757
$this->mapping = $mapping ?? $this->mapping;

src/installers.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@
3535
new FilesInstaller($mappingResolver, $fileInstaller, $io),
3636
new ArchiveExcludeInstaller($mappingResolver, $io),
3737
new PackagesInstaller($composer, $typeResolver, $io),
38-
new ConfigInstaller($configResolver)
38+
new ConfigInstaller($configResolver),
3939
];

0 commit comments

Comments
 (0)