Skip to content

Commit

Permalink
Add test for disabling the dependency patches resolver + fix a bug fo…
Browse files Browse the repository at this point in the history
…r disabling other kinds of capabilities
  • Loading branch information
cweagans committed Feb 14, 2024
1 parent 68c371c commit 5d52614
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ public function downloadPatch(Patch $patch)
}

foreach ($this->getDownloaders() as $downloader) {
if (in_array(get_class($downloader), $this->disabledDownloaders, true)) {
$class = "\\" . get_class($downloader);
if (in_array($class, $this->disabledDownloaders, true)) {
$this->io->write(
'<info> - Skipping downloader ' . get_class($downloader) . '</info>',
'<info> - Skipping downloader ' . $class . '</info>',
true,
IOInterface::VERBOSE
);
Expand Down
5 changes: 3 additions & 2 deletions src/Patcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ public function __construct(Composer $composer, IOInterface $io, array $disabled
public function applyPatch(Patch $patch, string $path): bool
{
foreach ($this->getPatchers() as $patcher) {
if (in_array(get_class($patcher), $this->disabledPatchers, true)) {
$class = "\\" . get_class($patcher);
if (in_array($class, $this->disabledPatchers, true)) {
$this->io->write(
'<info> - Skipping patcher ' . get_class($patcher) . '</info>',
'<info> - Skipping patcher ' . $class . '</info>',
true,
IOInterface::VERBOSE
);
Expand Down
6 changes: 4 additions & 2 deletions src/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ public function loadFromResolvers(): PatchCollection
// Let each resolver discover patches and add them to the PatchCollection.
/** @var ResolverInterface $resolver */
foreach ($this->getPatchResolvers() as $resolver) {
if (in_array(get_class($resolver), $this->disabledResolvers, true)) {
$class = "\\" . get_class($resolver);

if (in_array($class, $this->disabledResolvers, true)) {
$this->io->write(
'<info> - Skipping resolver ' . get_class($resolver) . '</info>',
'<info> - Skipping resolver ' . $class . '</info>',
true,
IOInterface::VERBOSE
);
Expand Down
33 changes: 33 additions & 0 deletions tests/_data/fixtures/disable-dependency-patches/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "cweagans/composer-patches-test-project",
"description": "Project for use in cweagans/composer-patches acceptance tests.",
"type": "project",
"license": "BSD-3-Clause",
"repositories": [
{
"type": "path",
"url": "../../../../"
},
{
"type": "path",
"url": "../../dep-test-package"
}
],
"require": {
"cweagans/composer-patches": "*@dev",
"cweagans/composer-patches-testrepo": "~1.0",
"cweagans/dep-test-package": "*@dev"
},
"config": {
"allow-plugins": {
"cweagans/composer-patches": true
}
},
"extra": {
"composer-patches": {
"disable-resolvers": [
"\\cweagans\\Composer\\Resolver\\Dependencies"
]
}
}
}
8 changes: 3 additions & 5 deletions tests/_data/fixtures/no-patchers-available/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
"extra": {
"composer-patches": {
"disable-patchers": [
"cweagans\\Composer\\Patcher\\BsdPatchPatcher",
"cweagans\\Composer\\Patcher\\GitPatcher",
"cweagans\\Composer\\Patcher\\GitInitPatcher",
"cweagans\\Composer\\Patcher\\GnuGPatchPatcher",
"cweagans\\Composer\\Patcher\\GnuPatchPatcher"
"\\cweagans\\Composer\\Patcher\\FreeformPatcher",
"\\cweagans\\Composer\\Patcher\\GitPatcher",
"\\cweagans\\Composer\\Patcher\\GitInitPatcher"
]
},
"patches": {
Expand Down
17 changes: 17 additions & 0 deletions tests/acceptance/DisableDependencyPatchesCept.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* @var \Codeception\Scenario $scenario
*/

use cweagans\Composer\Tests\AcceptanceTester;

$I = new AcceptanceTester($scenario);
$I->wantTo('disable resolving patches from dependencies (and test disabling resolvers in general)');
$I->amInPath(codecept_data_dir('fixtures/disable-dependency-patches'));
$I->runComposerCommand('install', ['-vvv']);
$I->dontSeeInComposerOutput('Resolving patches from dependencies');
$I->dontSeeInComposerOutput('Patching cweagans/commposer-patches-testrepo');
$I->dontSeeFileFound('OneMoreTest.php', 'vendor/cweagans/composer-patches-testrepo/src');
$I->openFile('patches.lock.json');
$I->seeInThisFile('6142bfcb78f54dfbf5247ae5e463f25bdb8fff1890806e2e45aa81a59c211653');

0 comments on commit 5d52614

Please sign in to comment.