Allow passing arrays to App::uses() #881

Closed
wants to merge 1 commit into
from
View
@@ -515,7 +515,23 @@ public static function objects($type, $path = null, $cache = true) {
* @return void
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/app.html#App::uses
*/
- public static function uses($className, $location) {
+ public static function uses($className, $location = null) {
+ if (is_array($className)) {
+ foreach ($className as $class => $location) {
+ self::$_classMap[$class] = $location;
+ }
+ return;
+ }
+
+ if (!$location) {
+ trigger_error(sprintf(
+ 'Missing argument 2 for %s(), called in %s on line %s',
+ __METHOD__,
+ __FILE__,
+ __LINE__
+ ), E_USER_ERROR);
+ }
+
self::$_classMap[$className] = $location;
}
@@ -812,6 +812,28 @@ public function testLoadClassInLibs() {
}
/**
+ * loading classes with a single call
+ */
+ public function testUsesWithArray() {
+ App::uses(array(
+ 'Foo' => 'Foo1',
+ 'Bar' => 'Bar1',
+ 'Baz' => 'Baz1'
+ ));
+
+ $this->assertEquals('Foo1', App::location('Foo'));
+ $this->assertEquals('Bar1', App::location('Bar'));
+ $this->assertEquals('Baz1', App::location('Baz'));
+ }
+
+/**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUsesError() {
+ App::uses('DoingItWrong');
+ }
+
+/**
* Tests that App::location() returns the defined path for a class
*
* @return void