Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add project-specific depth settings #452

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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];
}
}