diff --git a/src/Composer/Util/ConfigValidator.php b/src/Composer/Util/ConfigValidator.php index e5f64ec23..407819b58 100644 --- a/src/Composer/Util/ConfigValidator.php +++ b/src/Composer/Util/ConfigValidator.php @@ -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"; diff --git a/tests/Composer/Test/Util/ConfigValidatorTest.php b/tests/Composer/Test/Util/ConfigValidatorTest.php index 3d0260832..157eba92e 100644 --- a/tests/Composer/Test/Util/ConfigValidatorTest.php +++ b/tests/Composer/Test/Util/ConfigValidatorTest.php @@ -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 + ); + } } diff --git a/tests/Composer/Test/Util/Fixtures/composer_scripts-descriptions.json b/tests/Composer/Test/Util/Fixtures/composer_scripts-descriptions.json new file mode 100644 index 000000000..8cf3bd501 --- /dev/null +++ b/tests/Composer/Test/Util/Fixtures/composer_scripts-descriptions.json @@ -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" + } +}