-
Notifications
You must be signed in to change notification settings - Fork 10
/
CompatabilityTest.php
133 lines (110 loc) · 3.54 KB
/
CompatabilityTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php declare(strict_types=1);
namespace PhpTuf\ComposerStager\Tests\Compatability;
use PhpTuf\ComposerStager\Tests\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process;
/** @coversNothing */
final class CompatabilityTest extends TestCase
{
// @see https://github.com/php-tuf/composer-stager/wiki/Library-compatibility-policy#drupal
private const SUPPORTED_DRUPAL_VERSIONS = [
// Current major, oldest supported minor.
'10.0.0',
'10.0.10',
// Current minor.
'10.1.0',
'10.1.2',
// Next minor dev.
'11.x-dev',
];
public static function setUpBeforeClass(): void
{
self::ensureFixtures();
}
/**
* Tests for Composer compatability with supported Drupal core versions.
*
* @dataProvider providerDrupalVersionCompatability
*
* @see ../../composer.json
*/
public function testDrupalVersionCompatability(string $versionConstraint): void
{
$fixtureDir = self::fixtureDir($versionConstraint);
$process = new Process([
'composer',
'require',
'--dry-run',
'php-tuf/composer-stager:@dev',
], $fixtureDir);
$process->run();
self::assertTrue($process->isSuccessful(), sprintf(
'Incompatible with Drupal core %s. Error output:%s%s ',
$versionConstraint,
PHP_EOL . PHP_EOL,
$process->getErrorOutput(),
));
}
public function providerDrupalVersionCompatability(): array
{
$data = [];
foreach (self::SUPPORTED_DRUPAL_VERSIONS as $datum) {
$data[$datum] = [$datum];
}
return $data;
}
private static function fixtureDir(string $versionConstraint): string
{
return self::makeAbsolute(
'drupal-' . $versionConstraint,
self::testPersistentFixturesAbsolute(),
);
}
private static function ensureFixtures(): void
{
foreach (self::SUPPORTED_DRUPAL_VERSIONS as $versionConstraint) {
self::ensureFixture($versionConstraint);
}
}
private static function ensureFixture(string $versionConstraint): void
{
if (self::fixtureExists($versionConstraint)) {
return;
}
self::generateFixture($versionConstraint);
}
private static function fixtureExists(string $versionConstraint): bool
{
$fixtureDir = self::fixtureDir($versionConstraint);
return file_exists($fixtureDir . '/composer.json');
}
public static function generateFixture(string $versionConstraint): void
{
$filesystem = new Filesystem();
$fixtureDir = self::fixtureDir($versionConstraint);
$filesystem->remove($fixtureDir);
// Create drupal/recommended-project.
(new Process([
'composer',
'create-project',
'--no-install',
'drupal/recommended-project:' . $versionConstraint,
$fixtureDir,
]))->mustRun();
// Require corresponding drupal/core-dev.
(new Process([
'composer',
'require',
'--no-install',
'drupal/core-dev:' . $versionConstraint,
], $fixtureDir))->mustRun();
// Add Composer Stager path repository.
(new Process([
'composer',
'config',
'repositories.php-tuf/composer-stager',
'path',
self::repositoryRootAbsolute(),
], $fixtureDir))->mustRun();
}
}