bark if the model doesn't exist

Getting the following warning:

    ReflectionException: Class Mock_Foo_e187b1d1 does not have a
constructor, so you cannot pass any constructor arguments

Is a much less obvious way of saying "the class you're trying to mock
doesn't exist". Be more explicit
This commit is contained in:
AD7six 2013-08-03 14:46:20 +00:00
parent 35b4ac0286
commit ff856b7ebb
2 changed files with 17 additions and 0 deletions

View file

@ -423,4 +423,15 @@ class CakeTestCaseTest extends CakeTestCase {
$this->assertTrue($Mock->save(array()));
$this->assertFalse($Mock->save(array()));
}
/**
* testGetMockForModelDoesNotExist
*
* @expectedException MissingModelException
* @expectedExceptionMessage Model IDoNotExist could not be found
* @return void
*/
public function testGetMockForModelDoesNotExist() {
$this->getMockForModel('IDoNotExist');
}
}

View file

@ -690,6 +690,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
* @param string $model
* @param mixed $methods
* @param array $config
* @throws MissingModelException
* @return Model
*/
public function getMockForModel($model, $methods = array(), $config = array()) {
@ -698,6 +699,11 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
list($plugin, $name) = pluginSplit($model, true);
App::uses($name, $plugin . 'Model');
$config = array_merge((array)$config, array('name' => $name));
if (!class_exists($name)) {
throw new MissingModelException(array($model));
}
$mock = $this->getMock($name, $methods, array($config));
ClassRegistry::removeObject($name);
ClassRegistry::addObject($name, $mock);