Skip to content

Commit 97ffd46

Browse files
authored
fix constraint to allow upgrading d9 to d10 (#6)
* test upgrading d9 to d10 * check -W * test with match all * update the update call for drupal core * add back setting constraint from lock * stop being fancy with upper constraint * fix phpunit * update readme
1 parent 966905a commit 97ffd46

File tree

5 files changed

+47
-29
lines changed

5 files changed

+47
-29
lines changed

.github/workflows/integration.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,43 @@ jobs:
7373
cd ~/drupal
7474
composer require drupal/purge:3.x-dev#1342bb92b5304c6c316357d2c2c71a62a34d3eff -W
7575
composer show drupal/purge
76+
d9_to_d10:
77+
runs-on: "ubuntu-latest"
78+
name: "D9 to D10"
79+
steps:
80+
- name: "Checkout"
81+
uses: "actions/checkout@v2"
82+
- name: "Install PHP"
83+
uses: "shivammathur/setup-php@v2"
84+
with:
85+
coverage: none
86+
php-version: 8.1
87+
tools: composer:v2
88+
extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv
89+
- name: Setup Drupal
90+
uses: bluehorndigital/setup-drupal@v1.0.3
91+
with:
92+
version: ^9
93+
path: ~/drupal
94+
- name: Require self
95+
run: |
96+
cd ~/drupal
97+
composer require mglaman/composer-drupal-lenient *@dev
98+
- name: Configure allowed list
99+
run: |
100+
cd ~/drupal
101+
composer config --merge --json extra.drupal-lenient.allowed-list '["drupal/purge"]'
102+
- name: Add module release
103+
run: |
104+
cd ~/drupal
105+
composer require drupal/purge:3.x-dev#1342bb92b5304c6c316357d2c2c71a62a34d3eff -W
106+
composer show drupal/purge
107+
- name: Upgrade Drupal
108+
run: |
109+
cd ~/drupal
110+
composer require drupal/core-recommended:^10@alpha drupal/core-dev:^10@alpha drupal/core-composer-scaffold:^10@alpha drupal/core-project-message:^10@alpha drush/drush:^11.0 guzzlehttp/guzzle:^7.0 --with-all-dependencies --no-update
111+
composer update --no-progress --prefer-dist
112+
- name: Show module
113+
run: |
114+
cd ~/drupal
115+
composer show drupal/purge

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ See [Add a composer plugin that supports 'composer require-lenient' to support m
1515

1616
This subscribes to `PluginEvents::PRE_POOL_CREATE` and filters packages. This is inspired by `symfony/flex`, but it does
1717
not filter out packages. It rewrites the `drupal/core` constraint on any package with a type of `drupal-*`,
18-
excluding `drupal-core`. The constraint is set to a maximum version of the installed `drupal/core` package version.
18+
excluding `drupal-core`. The constraint is set to `'^8 || ^9 || ^10'` for `drupal/core`.
1919

2020
## Try it
2121

src/PackageRequiresAdjuster.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Composer\Semver\Constraint\Constraint;
1212
use Composer\Semver\Constraint\ConstraintInterface;
1313
use Composer\Semver\Constraint\MatchAllConstraint;
14+
use Composer\Semver\Constraint\MultiConstraint;
15+
use Composer\Semver\VersionParser;
1416

1517
final class PackageRequiresAdjuster
1618
{
@@ -19,17 +21,8 @@ final class PackageRequiresAdjuster
1921
public function __construct(
2022
private readonly Composer $composer
2123
) {
22-
$this->drupalCoreConstraint = new MatchAllConstraint();
23-
}
24-
25-
public function setDrupalCoreConstraint(): void
26-
{
27-
$locker = $this->composer->getLocker();
28-
foreach ($locker->getLockedRepository()->getPackages() as $package) {
29-
if ($package->getType() === 'drupal-core') {
30-
$this->drupalCoreConstraint = new Constraint('<=', $package->getVersion());
31-
}
32-
}
24+
$this->drupalCoreConstraint = (new VersionParser())
25+
->parseConstraints('^8 || ^9 || ^10');
3326
}
3427

3528
public function applies(PackageInterface $package): bool

src/Plugin.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ final class Plugin implements PluginInterface, EventSubscriberInterface
1717

1818
public function modifyPackages(PrePoolCreateEvent $event): void
1919
{
20-
$this->packageRequiresAdjuster->setDrupalCoreConstraint();
21-
2220
$packages = $event->getPackages();
2321
foreach ($packages as $package) {
2422
if ($this->packageRequiresAdjuster->applies($package)) {

tests/PackageRequiresAdjusterTest.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
use Composer\Package\RootPackage;
1111
use Composer\Repository\LockArrayRepository;
1212
use Composer\Semver\Constraint\Constraint;
13-
use Composer\Semver\Constraint\ConstraintInterface;
1413
use Composer\Semver\Constraint\MultiConstraint;
15-
use Composer\Semver\VersionParser;
1614
use PHPUnit\Framework\TestCase;
1715

1816
/**
@@ -74,7 +72,6 @@ public function provideTypes(): array
7472
/**
7573
* @covers ::__construct
7674
* @covers ::adjust
77-
* @covers ::setDrupalCoreConstraint
7875
*
7976
* @dataProvider provideAdjustData
8077
*/
@@ -84,16 +81,6 @@ public function testAdjust(?string $coreVersion, string $expectedCoreConstraintS
8481
$root = new RootPackage('foo', '1.0', '1.0');
8582
$composer->setPackage($root);
8683
$adjuster = new PackageRequiresAdjuster($composer);
87-
if ($coreVersion !== null) {
88-
$corePackage = new Package('foo', $coreVersion, $coreVersion);
89-
$corePackage->setType('drupal-core');
90-
$locker = $this->createStub(Locker::class);
91-
$lockedRepository = $this->createStub(LockArrayRepository::class);
92-
$lockedRepository->method('getPackages')->willReturn([$corePackage]);
93-
$locker->method('getLockedRepository')->willReturn($lockedRepository);
94-
$composer->setLocker($locker);
95-
$adjuster->setDrupalCoreConstraint();
96-
}
9784
$originalDrupalCoreConstraint = new MultiConstraint([
9885
new Constraint('>=', '8.0'),
9986
new Constraint('>=', '9.0'),
@@ -139,8 +126,8 @@ public function testAdjust(?string $coreVersion, string $expectedCoreConstraintS
139126
public function provideAdjustData(): array
140127
{
141128
return [
142-
[null, '*'],
143-
['10.0.0-alpha5', '<= 10.0.0-alpha5'],
129+
[null, '^8 || ^9 || ^10'],
130+
['10.0.0-alpha5', '^8 || ^9 || ^10'],
144131
];
145132
}
146133
}

0 commit comments

Comments
 (0)