From ffd45b7678e4f87b95178faf91f12a3ad6ebc142 Mon Sep 17 00:00:00 2001 From: Beau Simensen Date: Thu, 25 Apr 2013 14:02:15 -0500 Subject: [PATCH] Validate autoload options are of a supported type Checks to ensure that the autoload options are one of the three supported autoload types. closes #952 --- .../Package/Loader/ValidatingArrayLoader.php | 10 ++++++++- .../Loader/ValidatingArrayLoaderTest.php | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index 87ce0036d..a5b6281a3 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -179,7 +179,15 @@ class ValidatingArrayLoader implements LoaderInterface } } - // TODO validate autoload + if ($this->validateArray('autoload') && !empty($this->config['autoload'])) { + $types = array('psr-0', 'classmap', 'files'); + foreach ($this->config['autoload'] as $type => $typeConfig) { + if (!in_array($type, $types)) { + $this->errors[] = 'autoload : invalid value ('.$type.'), must be one of '.implode(', ', $types); + unset($this->config['autoload'][$type]); + } + } + } // TODO validate dist // TODO validate source diff --git a/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php b/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php index 23686d08f..262c24bf6 100644 --- a/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php @@ -234,6 +234,28 @@ class ValidatingArrayLoaderTest extends \PHPUnit_Framework_TestCase 'support.source : invalid value, must be a string', ) ), + array( + array( + 'name' => 'foo/bar', + 'autoload' => 'strings', + ), + array( + 'autoload : should be an array, string given' + ) + ), + array( + array( + 'name' => 'foo/bar', + 'autoload' => array( + 'psr0' => array( + 'foo' => 'src', + ), + ), + ), + array( + 'autoload : invalid value (psr0), must be one of psr-0, classmap, files' + ) + ), ); }