Skip to content

Commit

Permalink
fix constraint to allow upgrading d9 to d10 (#6)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mglaman authored Jun 24, 2022
1 parent 966905a commit 97ffd46
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 29 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,43 @@ jobs:
cd ~/drupal
composer require drupal/purge:3.x-dev#1342bb92b5304c6c316357d2c2c71a62a34d3eff -W
composer show drupal/purge
d9_to_d10:
runs-on: "ubuntu-latest"
name: "D9 to D10"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: none
php-version: 8.1
tools: composer:v2
extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv
- name: Setup Drupal
uses: bluehorndigital/[email protected]
with:
version: ^9
path: ~/drupal
- name: Require self
run: |
cd ~/drupal
composer require mglaman/composer-drupal-lenient *@dev
- name: Configure allowed list
run: |
cd ~/drupal
composer config --merge --json extra.drupal-lenient.allowed-list '["drupal/purge"]'
- name: Add module release
run: |
cd ~/drupal
composer require drupal/purge:3.x-dev#1342bb92b5304c6c316357d2c2c71a62a34d3eff -W
composer show drupal/purge
- name: Upgrade Drupal
run: |
cd ~/drupal
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
composer update --no-progress --prefer-dist
- name: Show module
run: |
cd ~/drupal
composer show drupal/purge
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ See [Add a composer plugin that supports 'composer require-lenient' to support m

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

## Try it

Expand Down
15 changes: 4 additions & 11 deletions src/PackageRequiresAdjuster.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Composer\Semver\Constraint\Constraint;
use Composer\Semver\Constraint\ConstraintInterface;
use Composer\Semver\Constraint\MatchAllConstraint;
use Composer\Semver\Constraint\MultiConstraint;
use Composer\Semver\VersionParser;

final class PackageRequiresAdjuster
{
Expand All @@ -19,17 +21,8 @@ final class PackageRequiresAdjuster
public function __construct(
private readonly Composer $composer
) {
$this->drupalCoreConstraint = new MatchAllConstraint();
}

public function setDrupalCoreConstraint(): void
{
$locker = $this->composer->getLocker();
foreach ($locker->getLockedRepository()->getPackages() as $package) {
if ($package->getType() === 'drupal-core') {
$this->drupalCoreConstraint = new Constraint('<=', $package->getVersion());
}
}
$this->drupalCoreConstraint = (new VersionParser())
->parseConstraints('^8 || ^9 || ^10');
}

public function applies(PackageInterface $package): bool
Expand Down
2 changes: 0 additions & 2 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ final class Plugin implements PluginInterface, EventSubscriberInterface

public function modifyPackages(PrePoolCreateEvent $event): void
{
$this->packageRequiresAdjuster->setDrupalCoreConstraint();

$packages = $event->getPackages();
foreach ($packages as $package) {
if ($this->packageRequiresAdjuster->applies($package)) {
Expand Down
17 changes: 2 additions & 15 deletions tests/PackageRequiresAdjusterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
use Composer\Package\RootPackage;
use Composer\Repository\LockArrayRepository;
use Composer\Semver\Constraint\Constraint;
use Composer\Semver\Constraint\ConstraintInterface;
use Composer\Semver\Constraint\MultiConstraint;
use Composer\Semver\VersionParser;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -74,7 +72,6 @@ public function provideTypes(): array
/**
* @covers ::__construct
* @covers ::adjust
* @covers ::setDrupalCoreConstraint
*
* @dataProvider provideAdjustData
*/
Expand All @@ -84,16 +81,6 @@ public function testAdjust(?string $coreVersion, string $expectedCoreConstraintS
$root = new RootPackage('foo', '1.0', '1.0');
$composer->setPackage($root);
$adjuster = new PackageRequiresAdjuster($composer);
if ($coreVersion !== null) {
$corePackage = new Package('foo', $coreVersion, $coreVersion);
$corePackage->setType('drupal-core');
$locker = $this->createStub(Locker::class);
$lockedRepository = $this->createStub(LockArrayRepository::class);
$lockedRepository->method('getPackages')->willReturn([$corePackage]);
$locker->method('getLockedRepository')->willReturn($lockedRepository);
$composer->setLocker($locker);
$adjuster->setDrupalCoreConstraint();
}
$originalDrupalCoreConstraint = new MultiConstraint([
new Constraint('>=', '8.0'),
new Constraint('>=', '9.0'),
Expand Down Expand Up @@ -139,8 +126,8 @@ public function testAdjust(?string $coreVersion, string $expectedCoreConstraintS
public function provideAdjustData(): array
{
return [
[null, '*'],
['10.0.0-alpha5', '<= 10.0.0-alpha5'],
[null, '^8 || ^9 || ^10'],
['10.0.0-alpha5', '^8 || ^9 || ^10'],
];
}
}

0 comments on commit 97ffd46

Please sign in to comment.