Browse Source

Show model type in MissingModelException message.

ADmad 12 years ago
parent
commit
90586cd632

+ 1 - 1
src/Model/Error/MissingModelException.php

@@ -22,6 +22,6 @@ use Cake\Error\Exception;
  */
 class MissingModelException extends Exception {
 
-	protected $_messageTemplate = 'Model class %s could not be found.';
+	protected $_messageTemplate = 'Model class "%s" of type "%s" could not be found.';
 
 }

+ 1 - 1
src/Model/ModelAwareTrait.php

@@ -93,7 +93,7 @@ trait ModelAwareTrait {
 		$factory = $this->_modelFactories[$type];
 		$this->{$modelClass} = $factory($plugin . $modelClass);
 		if (!$this->{$modelClass}) {
-			throw new Error\MissingModelException($modelClass);
+			throw new Error\MissingModelException([$modelClass, $type]);
 		}
 		return true;
 	}

+ 17 - 0
tests/TestCase/Model/ModelAwareTraitTest.php

@@ -85,4 +85,21 @@ class ModelAwareTraitTest extends TestCase {
 		$this->assertEquals('Magic', $stub->Magic->name);
 	}
 
+/**
+ * test MissingModelException being thrown
+ *
+ * @return void
+ * @expectedException Cake\Model\Error\MissingModelException
+ * @expectedExceptionMessage Model class "Magic" of type "Test" could not be found.
+ */
+	public function testMissingModelException() {
+		$stub = new Stub();
+
+		$stub->modelFactory('Test', function($name) {
+			return false;
+		});
+
+		$stub->loadModel('Magic', 'Test');
+	}
+
 }