Skip to content

Commit e01db81

Browse files
author
Stefan Boonstra
committed
WIP
TODO: Fix bin/youwe-container-detected-exec
1 parent 3e1206b commit e01db81

19 files changed

+222
-232
lines changed

.github/workflows/testing-suite.yml

+17-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ jobs:
55
strategy:
66
matrix:
77
image: [
8-
'srcoder/development-php:php74-fpm',
9-
'srcoder/development-php:php80-fpm',
10-
'srcoder/development-php:php81-fpm'
8+
'srcoder/development-php:php81-fpm',
9+
'srcoder/development-php:php82-fpm'
1110
]
1211
runs-on: ubuntu-latest
1312
container:
@@ -16,8 +15,22 @@ jobs:
1615
- name: Checkout
1716
uses: actions/checkout@v2
1817
- name: Testing Suite
18+
# We are purposefully skipping the phpunit task since it is writting for phpunit ^12 and php >= 8.3
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
22+
composer2 exec -v grumphp -- run --tasks=composer,jsonlint,xmllint,yamllint,phpcs,phplint,phpmd,phpstan,securitychecker_enlightn
23+
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
32+
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
2336
shell: bash

CONTRIBUTING.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Before opening a PR with changes, make sure all the linting steps are successful.
2+
3+
The require-dev dependency for phpunit is set to @stable for the github actions, but the tests themselves\
4+
assume they are running against PHPUnit 12 and php >= 8.3. The github actions only run phpunit tests against\
5+
a php 8.3 container.
6+
17
If a PR is approved please ask one of the following maintainers to get it merged:
2-
[Igor Wulff](https://github.com/igorwulff)
3-
[Dan Wallis](https://github.com/fredden)
8+
9+
- [Igor Wulff](https://github.com/igorwulff)
10+
- [Leon Helmus](https://github.com/leonhelmus)
11+
- [Rutger Rademakers](https://github.com/rutgerrademaker)

composer.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,25 @@
2424
}
2525
],
2626
"require": {
27-
"php": "^7.2 || ^8.0",
27+
"php": "^8.1",
2828
"composer-plugin-api": "^1.1 || ^2.0",
2929
"enlightn/security-checker": "^1.5 || ^2.0",
3030
"kint-php/kint": "@stable",
3131
"php-parallel-lint/php-parallel-lint": "^1.2",
3232
"phpro/grumphp-shim": "^1.13",
3333
"phpstan/phpstan": "@stable",
34-
"phpunit/phpunit": "@stable",
3534
"youwe/coding-standard": "^3.5.0",
36-
"youwe/coding-standard-phpstorm": "^2.3.0",
3735
"youwe/composer-dependency-installer": "^1.4.0",
3836
"youwe/composer-file-installer": "^1.2.0"
3937
},
38+
"suggest": {
39+
"phpunit/phpunit": "^9.6 || ^10.5 || ^11.5 || ^12.0",
40+
"youwe/coding-standard-phpstorm": "^2.3.0"
41+
},
4042
"require-dev": {
4143
"composer/composer": "@stable",
42-
"mikey179/vfsstream": "@stable"
44+
"mikey179/vfsstream": "@stable",
45+
"phpunit/phpunit": "@stable"
4346
},
4447
"replace": {
4548
"sensiolabs/security-checker": "*"

phpstan.neon

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
parameters:
22
excludePaths:
33
- src/installers.php
4+
- tests/*
45
ignoreErrors:
56
- '#Property Mediact\\TestingSuite\\Composer\\Installer\\ConfigInstaller::\$io is never read, only written\.#'

src/Factory/ProcessFactory.php

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class ProcessFactory implements ProcessFactoryInterface
2323
public function create(string $commandLine): Process
2424
{
2525
// See https://github.com/composer/composer/blob/1.10.17/src/Composer/Util/ProcessExecutor.php#L68:L72
26+
// @phpstan-ignore-next-line because phpstan can see it's available, but we cannot guarantee symfony >= 4.2 upstream
2627
return method_exists(Process::class, 'fromShellCommandline')
2728
? Process::fromShellCommandline($commandLine) // Symfony >= 4.2
2829
: new Process($commandLine); // Symfony < 4.2

src/Installer/ArchiveExcludeInstaller.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
use Youwe\TestingSuite\Composer\MappingResolver;
1717

1818
/**
19-
* @SuppressWarnings(PHPMD.ShortVariable)
20-
* @SuppressWarnings(PHPMD.StaticAccess)
19+
* @SuppressWarnings("PHPMD.ShortVariable")
20+
* @SuppressWarnings("PHPMD.StaticAccess")
2121
*/
2222
class ArchiveExcludeInstaller implements InstallerInterface
2323
{

src/Installer/ConfigInstaller.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
use Youwe\TestingSuite\Composer\ConfigResolver;
1616

1717
/**
18-
* @SuppressWarnings(PHPMD.ShortVariable)
19-
* @SuppressWarnings(PHPMD.StaticAccess)
18+
* @SuppressWarnings("PHPMD.ShortVariable")
19+
* @SuppressWarnings("PHPMD.StaticAccess")
2020
*/
2121
class ConfigInstaller implements InstallerInterface
2222
{

src/Installer/FilesInstaller.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Youwe\TestingSuite\Composer\MappingResolver;
1616

1717
/**
18-
* @SuppressWarnings(PHPMD.ShortVariable)
18+
* @SuppressWarnings("PHPMD.ShortVariable")
1919
*/
2020
class FilesInstaller implements InstallerInterface
2121
{
@@ -72,7 +72,7 @@ public function install(): void
7272
/**
7373
* @param FileMappingInterface $unixFileMapping
7474
*
75-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
75+
* @SuppressWarnings("PHPMD.CyclomaticComplexity")
7676
*
7777
* @return void
7878
*/

src/Installer/PackagesInstaller.php

+27-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Youwe\TestingSuite\Composer\ProjectTypeResolver;
1717

1818
/**
19-
* @SuppressWarnings(PHPMD.ShortVariable)
19+
* @SuppressWarnings("PHPMD.ShortVariable")
2020
*/
2121
class PackagesInstaller implements InstallerInterface
2222
{
@@ -33,37 +33,49 @@ class PackagesInstaller implements InstallerInterface
3333
private $io;
3434

3535
/** @var array */
36-
private $mapping = [
37-
MappingResolver::DEFAULT_MAPPING_TYPE => [],
36+
public $mapping = [
37+
MappingResolver::DEFAULT_MAPPING_TYPE => [
38+
[
39+
'name' => 'phpunit/phpunit',
40+
'version' => '@stable',
41+
'dev' => true,
42+
'allowVersionOverride' => false
43+
]
44+
],
3845
'magento1' => [
3946
[
4047
'name' => 'youwe/coding-standard-magento1',
4148
'version' => '^1.3.0',
42-
'dev' => true
49+
'dev' => true,
50+
'allowVersionOverride' => true
4351
]
4452
],
4553
'magento2' => [
4654
[
4755
'name' => 'youwe/coding-standard-magento2',
4856
'version' => '^2.0.0',
49-
'dev' => true
57+
'dev' => true,
58+
'allowVersionOverride' => true
5059
],
5160
[
5261
'name' => 'phpstan/extension-installer',
5362
'version' => '^1.3',
54-
'dev' => true
63+
'dev' => true,
64+
'allowVersionOverride' => true,
5565
],
5666
[
5767
'name' => 'bitexpert/phpstan-magento',
5868
'version' => '~0.30',
59-
'dev' => true
69+
'dev' => true,
70+
'allowVersionOverride' => true,
6071
],
6172
],
6273
'laravel' => [
6374
[
6475
'name' => 'elgentos/laravel-coding-standard',
6576
'version' => '^1.0.0',
66-
'dev' => true
77+
'dev' => true,
78+
'allowVersionOverride' => true,
6779
]
6880
]
6981
];
@@ -99,19 +111,21 @@ public function __construct(
99111
public function install(): void
100112
{
101113
$type = $this->typeResolver->resolve();
102-
if (!isset($this->mapping[$type])) {
103-
return;
104-
}
114+
$projectTypePackages = $this->mapping[$type] ?? [];
115+
$packagesToInstall = array_merge($projectTypePackages, $this->mapping[MappingResolver::DEFAULT_MAPPING_TYPE]);
105116

106-
foreach ($this->mapping[$type] as $package) {
117+
foreach ($packagesToInstall as $package) {
107118
if (!$this->isPackageRequired($package['name'], $package['version'])) {
108119
$this->io->write(
109120
sprintf('Requiring package %s', $package['name'])
110121
);
111122

112123
$this->installer->installPackage(
113124
$package['name'],
114-
$package['version']
125+
$package['version'],
126+
true,
127+
false,
128+
$package['allowVersionOverride']
115129
);
116130
}
117131
}

src/Plugin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Youwe\TestingSuite\Composer\Installer\InstallerInterface;
1717

1818
/**
19-
* @SuppressWarnings(PHPMD.ShortVariable)
19+
* @SuppressWarnings("PHPMD.ShortVariable")
2020
*/
2121
class Plugin implements PluginInterface, EventSubscriberInterface
2222
{

tests/ConfigResolverTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010
namespace Youwe\TestingSuite\Composer\Tests;
1111

1212
use org\bovigo\vfs\vfsStream;
13+
use PHPUnit\Framework\Attributes\CoversMethod;
14+
use PHPUnit\Framework\MockObject\Exception;
1315
use PHPUnit\Framework\TestCase;
1416
use Youwe\TestingSuite\Composer\ConfigResolver;
1517
use Youwe\TestingSuite\Composer\ProjectTypeResolver;
1618

1719
/**
18-
* @coversDefaultClass \Youwe\TestingSuite\Composer\ConfigResolver
19-
* @SuppressWarnings(PHPMD)
20+
* @phpcs:disable GlobalPhpUnit.Coverage.CoversTag.CoversTagMissing
2021
*/
22+
#[CoversMethod(ConfigResolver::class, '__construct')]
23+
#[CoversMethod(ConfigResolver::class, 'resolve')]
2124
class ConfigResolverTest extends TestCase
2225
{
2326
/**
24-
* @return void
25-
*
26-
* @covers ::__construct
27-
* @covers ::resolve
27+
* @throws Exception
2828
*/
2929
public function testResolve(): void
3030
{

tests/Factory/ProcessFactoryTest.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@
99

1010
namespace Youwe\TestingSuite\Composer\Tests\Factory;
1111

12+
use PHPUnit\Framework\Attributes\CoversMethod;
1213
use PHPUnit\Framework\TestCase;
1314
use Symfony\Component\Process\Process;
1415
use Youwe\TestingSuite\Composer\Factory\ProcessFactory;
1516

1617
/**
17-
* @coversDefaultClass \Youwe\TestingSuite\Composer\Factory\ProcessFactory
18+
* @phpcs:disable GlobalPhpUnit.Coverage.CoversTag.CoversTagMissing
1819
*/
20+
#[CoversMethod(ProcessFactory::class, 'create')]
1921
class ProcessFactoryTest extends TestCase
2022
{
21-
/**
22-
* @return void
23-
*
24-
* @covers ::create
25-
*/
26-
public function testCreate()
23+
public function testCreate(): void
2724
{
2825
$factory = new ProcessFactory();
2926

tests/Installer/ArchiveExcludeInstallerTest.php

+11-30
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,33 @@
1313
use Composer\Json\JsonFile;
1414
use org\bovigo\vfs\vfsStream;
1515
use org\bovigo\vfs\vfsStreamDirectory;
16-
use PHPUnit\Framework\MockObject\MockObject;
16+
use PHPUnit\Framework\Attributes\CoversMethod;
17+
use PHPUnit\Framework\Attributes\DataProvider;
18+
use PHPUnit\Framework\MockObject\Exception;
1719
use PHPUnit\Framework\TestCase;
1820
use Youwe\FileMapping\FileMappingInterface;
1921
use Youwe\FileMapping\FileMappingReaderInterface;
2022
use Youwe\TestingSuite\Composer\Installer\ArchiveExcludeInstaller;
2123
use Youwe\TestingSuite\Composer\MappingResolver;
2224

2325
/**
24-
* @coversDefaultClass \Youwe\TestingSuite\Composer\Installer\ArchiveExcludeInstaller
25-
* @SuppressWarnings(PHPMD)
26+
* @phpcs:disable GlobalPhpUnit.Coverage.CoversTag.CoversTagMissing
2627
*/
28+
#[CoversMethod(ArchiveExcludeInstaller::class, '__construct')]
29+
#[CoversMethod(ArchiveExcludeInstaller::class, 'install')]
2730
class ArchiveExcludeInstallerTest extends TestCase
2831
{
2932
/**
30-
* @param array $existingFiles
31-
* @param array $files
32-
* @param array $defaults
33-
* @param array $definition
34-
* @param array $expected
35-
*
36-
* @return void
37-
*
38-
* @dataProvider dataProvider
39-
*
40-
* @covers ::__construct
41-
* @covers ::install
33+
* @throws Exception
4234
*/
35+
#[DataProvider('dataProvider')]
4336
public function testInstall(
4437
array $existingFiles,
4538
array $files,
4639
array $defaults,
4740
array $definition,
4841
array $expected
49-
) {
42+
): void {
5043
$file = $this->createMock(JsonFile::class);
5144
$resolver = $this->createMock(MappingResolver::class);
5245
$io = $this->createMock(IOInterface::class);
@@ -79,10 +72,7 @@ public function testInstall(
7972
$installer->install();
8073
}
8174

82-
/**
83-
* @return array
84-
*/
85-
public function dataProvider(): array
75+
public static function dataProvider(): array
8676
{
8777
return [
8878
[
@@ -122,21 +112,17 @@ public function dataProvider(): array
122112
}
123113

124114
/**
125-
* @param array $files
126-
*
127-
* @return FileMappingReaderInterface
115+
* @throws Exception
128116
*/
129117
private function createReaderMock(array $files): FileMappingReaderInterface
130118
{
131-
/** @var FileMappingReaderInterface|MockObject $mock */
132119
$mock = $this->createMock(FileMappingReaderInterface::class);
133120

134121
$valids = array_fill(0, count($files), true);
135122
$valids[] = false;
136123

137124
$mappings = array_map(
138125
function (string $file): FileMappingInterface {
139-
/** @var FileMappingInterface|MockObject $mapping */
140126
$mapping = $this->createMock(FileMappingInterface::class);
141127
$mapping
142128
->expects(self::any())
@@ -166,11 +152,6 @@ function (string $file): FileMappingInterface {
166152
return $mock;
167153
}
168154

169-
/**
170-
* @param array $files
171-
*
172-
* @return vfsStreamDirectory
173-
*/
174155
private function createFilesystem(array $files): vfsStreamDirectory
175156
{
176157
return vfsStream::setup(

0 commit comments

Comments
 (0)