1
0
Fork 0

Merge pull request #9327 from naderman/backport-validate-provide-replace-req

Validate: Warn about providing or replacing packages you require
pull/9347/head
Jordi Boggiano 2020-10-24 09:32:49 +02:00 committed by GitHub
commit 11e652061e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 0 deletions

View File

@ -138,6 +138,22 @@ class ConfigValidator
}
}
// check for meaningless provide/replace satisfying requirements
foreach (array('provide', 'replace') as $linkType) {
if (isset($manifest[$linkType])) {
foreach (array('require', 'require-dev') as $requireType) {
if (isset($manifest[$requireType])) {
foreach ($manifest[$linkType] as $provide => $constraint) {
if (isset($manifest[$requireType][$provide])) {
$warnings[] = 'The package ' . $provide . ' in '.$requireType.' is also listed in '.$linkType.' which satisfies the requirement. Remove it from '.$linkType.' if you wish to install it.';
}
}
}
}
}
}
// check for commit references
$require = isset($manifest['require']) ? $manifest['require'] : array();
$requireDev = isset($manifest['require-dev']) ? $manifest['require-dev'] : array();

View File

@ -45,4 +45,23 @@ class ConfigValidatorTest extends TestCase
$warnings
);
}
public function testConfigValidatorWarnsOnUnnecessaryProvideReplace()
{
$configValidator = new ConfigValidator(new NullIO());
list(, , $warnings) = $configValidator->validate(__DIR__ . '/Fixtures/composer_provide-replace-requirements.json');
$this->assertContains(
'The package a/a in require is also listed in provide which satisfies the requirement. Remove it from provide if you wish to install it.',
$warnings
);
$this->assertContains(
'The package b/b in require is also listed in replace which satisfies the requirement. Remove it from replace if you wish to install it.',
$warnings
);
$this->assertContains(
'The package c/c in require-dev is also listed in provide which satisfies the requirement. Remove it from provide if you wish to install it.',
$warnings
);
}
}

View File

@ -0,0 +1,17 @@
{
"license": "MIT",
"require": {
"a/a": "^1.0",
"b/b": "^2.0"
},
"require-dev": {
"c/c": "^2.0"
},
"provide": {
"a/a": "1.0.0",
"c/c": "1.0.0"
},
"replace": {
"b/b": "3.0.0"
}
}