Skip to content

Commit

Permalink
Merge pull request #452 from cweagans/451-project-specific-depth
Browse files Browse the repository at this point in the history
Add project-specific depth settings
  • Loading branch information
cweagans committed Feb 8, 2023
2 parents caeb55f + ee00e41 commit 2ed32a4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Plugin/Patches.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ public function activate(Composer $composer, IOInterface $io): void
'type' => 'int',
'default' => 1,
],
'package-depths' => [
'type' => 'list',
'default' => [],
],
'patches-file' => [
'type' => 'string',
'default' => '',
Expand Down Expand Up @@ -236,6 +240,7 @@ public function guessDepth(Patch $patch)
$patch = $event->getPatch();

$depth = $patch->depth ??
$this->getConfig('package-depths')[$patch->package] ??
Util::getDefaultPackagePatchDepth($patch->package) ??
$this->getConfig('default-patch-depth');
$patch->depth = $depth;
Expand Down
59 changes: 59 additions & 0 deletions tests/unit/PatchesPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

use Codeception\Test\Unit;
use Composer\Composer;
use Composer\EventDispatcher\EventDispatcher;
use Composer\IO\NullIO;
use Composer\Package\RootPackage;
use cweagans\Composer\Patch;
use cweagans\Composer\Plugin\Patches;

class PatchesPluginTest extends Unit
Expand All @@ -32,4 +34,61 @@ public function testActivate()
$io = new NullIO();
$plugin->activate($composer, $io);
}

/**
* Test the patch depth settings.
*
* @dataProvider guessDepthDataProvider
*/
public function testGuessDepth(Patches $plugin, Patch $patch, int $expectedDepth)
{
$plugin->guessDepth($patch);
$this->assertEquals($expectedDepth, $patch->depth);
}

/**
* Provides data to testGuessDepth().
*/
public function guessDepthDataProvider()
{
$package = new RootPackage('cweagans/composer-patches', '0.0.0.0', '0.0.0');
$package->setExtra([]);

$io = new NullIO();

$composer = new Composer();
$composer->setPackage($package);
$composer->setEventDispatcher(new EventDispatcher($composer, $io));

$plugin = new Patches();
$plugin->activate($composer, $io);

$patch = new Patch();
$patch->package = 'some/package';
yield 'global default depth' => [$plugin, $patch, 1];

$patch = new Patch();
$patch->depth = 123;
yield 'depth set on patch' => [$plugin, $patch, 123];

$patch = new Patch();
$patch->package = 'drupal/core';
yield 'depth set in global package override list' => [$plugin, $patch, 2];

$package = new RootPackage('cweagans/composer-patches', '0.0.0.0', '0.0.0');
$package->setExtra([
'composer-patches' => [
'package-depths' => [
'some/package' => 234,
],
],
]);
$composer->setPackage($package);
$plugin = new Patches();
$plugin->activate($composer, $io);

$patch = new Patch();
$patch->package = 'some/package';
yield 'depth set in project package override list' => [$plugin, $patch, 234];
}
}

0 comments on commit 2ed32a4

Please sign in to comment.