Browse Source

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
AD7six 12 years ago
parent
commit
ff856b7ebb

+ 11 - 0
lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php

@@ -423,4 +423,15 @@ class CakeTestCaseTest extends CakeTestCase {
 		$this->assertTrue($Mock->save(array()));
 		$this->assertTrue($Mock->save(array()));
 		$this->assertFalse($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');
+	}
 }
 }

+ 6 - 0
lib/Cake/TestSuite/CakeTestCase.php

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