Skip to content

Commit

Permalink
Show model type in MissingModelException message.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Apr 17, 2014
1 parent 282c6e0 commit 90586cd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Model/Error/MissingModelException.php
Expand Up @@ -22,6 +22,6 @@
*/
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.';

}
2 changes: 1 addition & 1 deletion src/Model/ModelAwareTrait.php
Expand Up @@ -93,7 +93,7 @@ public function loadModel($modelClass = null, $type = 'Table') {
$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;
}
Expand Down
17 changes: 17 additions & 0 deletions tests/TestCase/Model/ModelAwareTraitTest.php
Expand Up @@ -85,4 +85,21 @@ public function testModelFactory() {
$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');
}

}

0 comments on commit 90586cd

Please sign in to comment.