/** * Loads the fixtures from the mongoFixtures array in the testCase into the mongoDataSource. * @param CakeTestCase $testCase * * @return bool * @throws Exception */ public static function loadMongoFixtures(CakeTestCase $testCase) { if (!isset($testCase->mongoFixtures) || !is_array($testCase->mongoFixtures)) { return false; } foreach ($testCase->mongoFixtures as $fixtureName) { list($plugin, $fixtureName) = explode('.', $fixtureName); $fixture = new $fixtureName(); $modelName = str_replace('Fixture', '', $fixtureName); $model = $testCase->getMockForModel($plugin . '.' . $modelName, array('test')); if (substr($model->useDbConfig, 0, 5) !== 'test_') { throw new InternalErrorException('The model for fixture ' . $fixtureName . ' does not have a test datasource.'); } self::$_models[] = $model; foreach ($fixture->collections as $collection => $documents) { $model->setSource($collection); $model->batchInsert($documents); } } return true; }
/** * {@inheritdoc} */ public function getMockForModel($model, $methods = array(), $config = array(), $registry = false) { $modelOriginal = ClassRegistry::init($model); $modelMock = parent::getMockForModel($model, $methods, $config); // Fix bug when not merging behaviors and findMethods recursively for mocks. // @see Model::__construct() line 717-724 if (get_parent_class($modelOriginal) !== 'AppModel') { $modelMock->findMethods = $modelOriginal->findMethods; $modelMock->Behaviors->init($modelMock->alias, $modelOriginal->actsAs); } if ($registry) { if (true === $registry) { list(, $registry) = pluginSplit($model); } if (ClassRegistry::isKeySet($registry)) { ClassRegistry::removeObject($registry); } ClassRegistry::addObject($registry, $modelMock); } return $modelMock; }