1
0
Fork 0

Validation warns if script description for nonexistent script is present

Fixes #7010
pull/7019/head
Martin Hujer 2018-01-17 19:15:06 +01:00
parent 015927d0b0
commit bbee0d7c6c
3 changed files with 33 additions and 0 deletions

View File

@ -118,6 +118,18 @@ class ConfigValidator
}
}
// report scripts-descriptions for non-existent scripts
$scriptsDescriptions = isset($manifest['scripts-descriptions']) ? $manifest['scripts-descriptions'] : array();
$scripts = isset($manifest['scripts']) ? $manifest['scripts'] : array();
foreach ($scriptsDescriptions as $scriptName => $scriptDescription) {
if (!array_key_exists($scriptName, $scripts)) {
$warnings[] = sprintf(
'Description for non-existent script "%s" found in "scripts-descriptions"',
$scriptName
);
}
}
// check for empty psr-0/psr-4 namespace prefixes
if (isset($manifest['autoload']['psr-0'][''])) {
$warnings[] = "Defining autoload.psr-0 with an empty namespace prefix is a bad idea for performance";

View File

@ -34,4 +34,15 @@ class ConfigValidatorTest extends TestCase
$warnings
);
}
public function testConfigValidatorWarnsOnScriptDescriptionForNonexistentScript()
{
$configValidator = new ConfigValidator(new NullIO());
list(, , $warnings) = $configValidator->validate(__DIR__ . '/Fixtures/composer_scripts-descriptions.json');
$this->assertContains(
'Description for non-existent script "phpcsxxx" found in "scripts-descriptions"',
$warnings
);
}
}

View File

@ -0,0 +1,10 @@
{
"scripts": {
"test": "phpunit",
"phpcs": "phpcs --standard=PSR2 src"
},
"scripts-descriptions": {
"test": "Launches the preconfigured PHPUnit",
"phpcsxxx": "Checks that the application code conforms to coding standard"
}
}