Browse Source

Set the entityClass for the mock

Berry Goudswaard 11 years ago
parent
commit
19e00a9f70
1 changed files with 10 additions and 0 deletions
  1. 10 0
      src/TestSuite/TestCase.php

+ 10 - 0
src/TestSuite/TestCase.php

@@ -567,6 +567,16 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
 		$options += TableRegistry::config($alias);
 		$options += TableRegistry::config($alias);
 
 
 		$mock = $this->getMock($options['className'], $methods, [$options]);
 		$mock = $this->getMock($options['className'], $methods, [$options]);
+
+		if (empty($options['entityClass']) && $mock->entityClass() === '\Cake\ORM\Entity') {
+			$parts = explode('\\', $options['className']);
+			$entityAlias = Inflector::singularize(substr(array_pop($parts), 0, -5));
+			$entityClass = implode('\\', array_slice($parts, 0, -1)) . '\Entity\\' . $entityAlias;
+			if (class_exists($entityClass)) {
+				$mock->entityClass($entityClass);
+			}
+		}
+
 		TableRegistry::set($baseClass, $mock);
 		TableRegistry::set($baseClass, $mock);
 		return $mock;
 		return $mock;
 	}
 	}