Permalink
Browse files

Allow passing arrays to App::uses()

  • Loading branch information...
dogmatic69 committed Sep 30, 2012
1 parent e1a0ce7 commit 9d1966c2b5dc6bdb69a6ad8502207d9c201e4938
Showing with 39 additions and 1 deletion.
  1. +17 −1 lib/Cake/Core/App.php
  2. +22 −0 lib/Cake/Test/Case/Core/AppTest.php
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;
}
@@ -811,6 +811,28 @@ public function testLoadClassInLibs() {
$this->assertTrue(class_exists('CustomLibClass'));
}
+/**
+ * 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
*

0 comments on commit 9d1966c

Please sign in to comment.