Created
November 7, 2013 09:41
-
-
Save akiyan/7351902 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function init_db_by_fixture() { | |
require_once CAKE . 'TestSuite' . DS . 'Fixture' . DS . 'CakeTestFixture.php'; | |
$model_files = glob(APP . 'Model/*.php'); | |
$fixture_db = ConnectionManager::getDataSource('test'); | |
foreach ($model_files as $path) { | |
$model = Inflector::camelize(str_replace('.php', '', basename($path))); | |
$modelObj = ClassRegistry::init($model); | |
if (isset($modelObj->useDbConfig) && $modelObj->useDbConfig == 'default' && is_string($modelObj->useTable)) { | |
$fixtureName = $model; | |
$fixture_path = TESTS . 'Fixture' . DS . $fixtureName . 'Fixture.php'; | |
if (is_readable($fixture_path)) { | |
$this->out($model); | |
$fixtureFile = $fixture_path; | |
require_once($fixtureFile); | |
$fixtureClass = Inflector::camelize($fixtureName) . 'Fixture'; | |
$fixture =& new $fixtureClass($fixture_db); | |
$fixture->drop($fixture_db); | |
$fixture->create($fixture_db); | |
$fixture->insert($fixture_db); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment