本文整理汇总了PHP中CakeTestFixture::create方法的典型用法代码示例。如果您正苦于以下问题:PHP CakeTestFixture::create方法的具体用法?PHP CakeTestFixture::create怎么用?PHP CakeTestFixture::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CakeTestFixture
的用法示例。
在下文中一共展示了CakeTestFixture::create方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Initializes this fixture class
*
* @return boolean
*/
public function create($db)
{
if (!empty($this->fields)) {
return parent::create($db);
}
return (bool) $db->execute(file_get_contents($this->_getFilePath()));
}
示例2: create
function create(&$db)
{
$result = parent::create($db);
if ($result) {
$db->execute('ALTER TABLE `items` CHANGE `provider_key` `provider_key` BIGINT( 20 ) NULL DEFAULT NULL ');
}
return $result;
}
示例3: create
/**
* Maps enum fields in the database to strings with a length of 64
*/
public function create($db)
{
foreach ($this->fields as $name => &$field) {
if (strstr($field['type'], "enum") !== false) {
$field['type'] = 'string';
$field['length'] = 64;
}
}
parent::create($db);
}
示例4: create
public function create($db)
{
parent::create($db);
return '
CREATE TABLE `multilanguage_model` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`object_id` int(11) unsigned NOT NULL,
`lang_code` varchar(5) NOT NULL,
`name` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8';
}
示例5: create
/**
* Initializes this fixture class
*
* @param DboSource $db
* @return boolean
*/
public function create($db)
{
if (!empty($this->fields)) {
return parent::create($db);
}
$source = ConnectionManager::getDataSource($this->sourceConfig);
$sourceTable = $source->fullTableName($this->table);
$query = sprintf('DROP TABLE IF EXISTS %s', $db->fullTableName($this->table));
$db->execute($query, ['log' => false]);
$query = sprintf('CREATE TABLE %s LIKE %s', $db->fullTableName($this->table), $sourceTable);
$db->execute($query, ['log' => false]);
$this->created[] = $db->configKeyName;
return true;
}
示例6: create
public function create($db)
{
$ok = parent::create($db);
// Workaround: CakeSchema cannot create FULLTEXT fixtures, so we change the table manually after creation
if ($ok) {
$query = "ALTER TABLE `{$this->table}` ADD FULLTEXT INDEX `data` (`data` ASC)";
try {
$db->rawQuery($query);
$this->created[] = $db->configKeyName;
} catch (Exception $e) {
$msg = __d('cake_dev', 'Fixture creation for "%s" failed "%s"', $this->table, $e->getMessage());
CakeLog::error($msg);
trigger_error($msg, E_USER_WARNING);
return false;
}
return true;
}
return false;
}
示例7: create
/**
* Run before all tests execute, should return SQL statement to create table for this fixture could be executed successfully.
*
* @param object $db An instance of the database object used to create the fixture table
* @return boolean True on success, false on failure
* @access public
* @ override
*/
public function create(&$db)
{
if (isset($this->fields) && !empty($this->fields) && empty($this->fields['tableParameters']['engine'])) {
$canUseMemory = true;
foreach ($this->fields as $field => $args) {
if (is_string($args)) {
$type = $args;
} elseif (!empty($args['type'])) {
$type = $args['type'];
} else {
continue;
}
if (in_array($type, array('blob', 'text', 'binary'))) {
$canUseMemory = false;
break;
}
}
if ($canUseMemory) {
$this->fields['tableParameters']['engine'] = 'MEMORY';
}
}
return parent::create($db);
}
示例8: _setupTable
/**
* Runs the drop and create commands on the fixtures if necessary.
*
* @param CakeTestFixture $fixture the fixture object to create
* @param DataSource $db the datasource instance to use
* @param boolean $drop whether drop the fixture if it is already created or not
* @return void
*/
protected function _setupTable($fixture, $db = null, $drop = true)
{
if (!$db) {
if (!empty($fixture->useDbConfig)) {
$db = ClassRegistry::getDataSource($fixture->useDbConfig);
} else {
$db = $this->_db;
}
}
if (!empty($fixture->created) && in_array($db->configKeyName, $fixture->created)) {
return;
}
$sources = $db->listSources();
$table = $db->config['prefix'] . $fixture->table;
if ($drop && in_array($table, $sources)) {
$fixture->drop($db);
$fixture->create($db);
} elseif (!in_array($table, $sources)) {
$fixture->create($db);
}
}
示例9: _setupTable
/**
* Runs the drop and create commands on the fixtures if necessary.
*
* @param CakeTestFixture $fixture the fixture object to create
* @param DataSource $db the datasource instance to use
* @param bool $drop whether drop the fixture if it is already created or not
* @return void
*/
protected function _setupTable($fixture, $db = null, $drop = true)
{
if (!$db) {
if (!empty($fixture->useDbConfig)) {
$db = ConnectionManager::getDataSource($fixture->useDbConfig);
} else {
$db = $this->_db;
}
}
if (!empty($fixture->created) && in_array($db->configKeyName, $fixture->created)) {
return;
}
$sources = (array) $db->listSources();
$table = $db->config['prefix'] . $fixture->table;
$exists = in_array($table, $sources);
if ($drop && $exists) {
$fixture->drop($db);
$fixture->create($db);
} elseif (!$exists) {
$fixture->create($db);
} else {
$fixture->created[] = $db->configKeyName;
}
}
示例10: startController
/**
* Callback issued when a controller's action is about to be invoked through testAction().
*
* @param Controller $controller Controller that's about to be invoked.
* @param array $params Additional parameters as sent by testAction().
* @return void
* @access public
*/
function startController(&$controller, $params = array())
{
if (isset($params['fixturize']) && (is_array($params['fixturize']) && !empty($params['fixturize']) || $params['fixturize'] === true)) {
if (!isset($this->db)) {
$this->_initDb();
}
if ($controller->uses === false) {
$list = array($controller->modelClass);
} else {
$list = is_array($controller->uses) ? $controller->uses : array($controller->uses);
}
$models = array();
ClassRegistry::config(array('ds' => $params['connection']));
foreach ($list as $name) {
if (is_array($params['fixturize']) && in_array($name, $params['fixturize']) || $params['fixturize'] === true) {
if (class_exists($name) || App::import('Model', $name)) {
$object = ClassRegistry::init($name);
//switch back to specified datasource.
$object->setDataSource($params['connection']);
$db = ConnectionManager::getDataSource($object->useDbConfig);
$db->cacheSources = false;
$models[$object->alias] = array('table' => $object->table, 'model' => $object->alias, 'key' => strtolower($name));
}
}
}
ClassRegistry::config(array('ds' => 'test_suite'));
if (!empty($models) && isset($this->db)) {
$this->_actionFixtures = array();
foreach ($models as $model) {
$fixture = new CakeTestFixture($this->db);
$fixture->name = $model['model'] . 'Test';
$fixture->table = $model['table'];
$fixture->import = array('model' => $model['model'], 'records' => true);
$fixture->init();
$fixture->create($this->db);
$fixture->insert($this->db);
$this->_actionFixtures[] = $fixture;
}
foreach ($models as $model) {
$object = ClassRegistry::getObject($model['key']);
if ($object !== false) {
$object->setDataSource('test_suite');
$object->cacheSources = false;
}
}
}
}
}
示例11: _setupTable
/**
* Runs the drop and create commands on the fixtures if necessary
*
* @param CakeTestFixture $fixture the fixture object to create
* @param DataSource $db the datasource instance to use
* @param boolean $drop whether drop the fixture if it is already created or not
* @return void
*/
protected function _setupTable($fixture, $db = null, $drop = true)
{
if (!$db) {
$db = $this->_db;
}
if (!empty($fixture->created) && $fixture->created == $db->configKeyName) {
return;
}
$cacheSources = $db->cacheSources;
$db->cacheSources = false;
$sources = $db->listSources();
$db->cacheSources = $cacheSources;
$table = $db->config['prefix'] . $fixture->table;
if ($drop && in_array($table, $sources)) {
$fixture->drop($db);
$fixture->create($db);
$fixture->created = $db->configKeyName;
} elseif (!in_array($table, $sources)) {
$fixture->create($db);
$fixture->created = $db->configKeyName;
}
}
示例12: create
public function create(&$db)
{
$db->columns['decimal'] = array('name' => 'decimal', 'formatter' => 'floatval');
return parent::create($db);
}
示例13: creaete
public function creaete($db)
{
$ret = parent::create($db);
var_dump($ret);
exit;
}