本文整理汇总了PHP中CakeTestCase::getMockForModel方法的典型用法代码示例。如果您正苦于以下问题:PHP CakeTestCase::getMockForModel方法的具体用法?PHP CakeTestCase::getMockForModel怎么用?PHP CakeTestCase::getMockForModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CakeTestCase
的用法示例。
在下文中一共展示了CakeTestCase::getMockForModel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadMongoFixtures
/**
* 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;
}
示例2: getMockForModel
/**
* {@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;
}