Skip to content

Commit 6ecc02e

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

11 files changed

+81
-71
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

+30-24
Original file line numberDiff line numberDiff line change
@@ -35,46 +35,51 @@ 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',
4140
'dev' => true,
42-
'allowVersionOverride' => false
41+
'updateDependencies' => true,
42+
'allowVersionOverride' => false,
4343
]
4444
],
4545
'magento1' => [
46-
[
47-
'name' => 'youwe/coding-standard-magento1',
46+
'youwe/coding-standard-magento1' => [
4847
'version' => '^1.3.0',
4948
'dev' => true,
50-
'allowVersionOverride' => true
49+
'updateDependencies' => true,
50+
'allowVersionOverride' => true,
5151
]
5252
],
5353
'magento2' => [
54-
[
55-
'name' => 'youwe/coding-standard-magento2',
54+
'phpunit/phpunit' => [
55+
'version' => '@stable',
56+
'dev' => false,
57+
'allowVersionOverride' => false,
58+
],
59+
'youwe/coding-standard-magento2' => [
5660
'version' => '^2.0.0',
5761
'dev' => true,
58-
'allowVersionOverride' => true
62+
'updateDependencies' => true,
63+
'allowVersionOverride' => true,
5964
],
60-
[
61-
'name' => 'phpstan/extension-installer',
65+
'phpstan/extension-installer' => [
6266
'version' => '^1.3',
6367
'dev' => true,
68+
'updateDependencies' => true,
6469
'allowVersionOverride' => true,
6570
],
66-
[
67-
'name' => 'bitexpert/phpstan-magento',
71+
'bitexpert/phpstan-magento' => [
6872
'version' => '~0.30',
6973
'dev' => true,
74+
'updateDependencies' => true,
7075
'allowVersionOverride' => true,
7176
],
7277
],
7378
'laravel' => [
74-
[
75-
'name' => 'elgentos/laravel-coding-standard',
79+
'elgentos/laravel-coding-standard' => [
7680
'version' => '^1.0.0',
7781
'dev' => true,
82+
'updateDependencies' => true,
7883
'allowVersionOverride' => true,
7984
]
8085
]
@@ -93,8 +98,8 @@ public function __construct(
9398
Composer $composer,
9499
ProjectTypeResolver $typeResolver,
95100
IOInterface $io,
96-
DependencyInstaller $installer = null,
97-
array $mapping = null
101+
?DependencyInstaller $installer = null,
102+
?array $mapping = null
98103
) {
99104
$this->composer = $composer;
100105
$this->typeResolver = $typeResolver;
@@ -112,19 +117,19 @@ public function install(): void
112117
{
113118
$type = $this->typeResolver->resolve();
114119
$projectTypePackages = $this->mapping[$type] ?? [];
115-
$packagesToInstall = array_merge($projectTypePackages, $this->mapping[MappingResolver::DEFAULT_MAPPING_TYPE]);
120+
$packagesToInstall = array_merge($this->mapping[MappingResolver::DEFAULT_MAPPING_TYPE], $projectTypePackages);
116121

117-
foreach ($packagesToInstall as $package) {
118-
if (!$this->isPackageRequired($package['name'], $package['version'])) {
122+
foreach ($packagesToInstall as $name => $package) {
123+
if (!$this->isPackageRequired($name, $package['version'])) {
119124
$this->io->write(
120-
sprintf('Requiring package %s', $package['name'])
125+
sprintf('Requiring package %s', $name)
121126
);
122127

123128
$this->installer->installPackage(
124-
$package['name'],
129+
$name,
125130
$package['version'],
126-
true,
127-
false,
131+
$package['dev'],
132+
$package['updateDependencies'],
128133
$package['allowVersionOverride']
129134
);
130135
}
@@ -135,6 +140,7 @@ public function install(): void
135140
* Whether a package has been required.
136141
*
137142
* @param string $packageName
143+
* @param string $version
138144
*
139145
* @return bool
140146
*/

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
];

tests/Installer/PackagesInstallerTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,18 @@ public function testCanMergeDefaultPackagesWhenInstalling(): void
6868

6969
$mapping = [
7070
MappingResolver::DEFAULT_MAPPING_TYPE => [
71-
[
72-
'name' => 'phpunit/phpunit',
71+
'phpunit/phpunit' => [
7372
'version' => '@stable',
7473
'dev' => true,
74+
'updateDependencies' => true,
7575
'allowVersionOverride' => false
7676
]
7777
],
7878
'magento1' => [
79-
[
80-
'name' => 'youwe/coding-standard-magento1',
79+
'youwe/coding-standard-magento1' => [
8180
'version' => '^1.3.0',
8281
'dev' => true,
82+
'updateDependencies' => false,
8383
'allowVersionOverride' => true
8484
]
8585
],

0 commit comments

Comments
 (0)