Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit ff856b7ebbfb074a2b0d418d07d25ce41ec3d38c 1 parent 35b4ac0
@AD7six AD7six authored
View
11 lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php
@@ -423,4 +423,15 @@ public function testGetMockForModelModel() {
$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
6 lib/Cake/TestSuite/CakeTestCase.php
@@ -690,6 +690,7 @@ protected function skipUnless($condition, $message = '') {
* @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 @@ public function getMockForModel($model, $methods = array(), $config = array()) {
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);
Please sign in to comment.
Something went wrong with that request. Please try again.