Validate: Warn about providing or replacing packages you require
parent
290450214e
commit
6409ed0fc2
|
@ -141,6 +141,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();
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue