mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding missing & operators.
Adding tests for run update. Adding -f param to schema run update to allow for testing and forcing of table comparison. Skips model checks and uses tables only instead.
This commit is contained in:
parent
dc4cfc59eb
commit
a7499be154
3 changed files with 94 additions and 4 deletions
|
@ -287,7 +287,7 @@ class SchemaShell extends Shell {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
function __create($Schema, $table = null) {
|
||||
function __create(&$Schema, $table = null) {
|
||||
$db =& ConnectionManager::getDataSource($this->Schema->connection);
|
||||
|
||||
$drop = $create = array();
|
||||
|
@ -331,11 +331,15 @@ class SchemaShell extends Shell {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
function __update($Schema, $table = null) {
|
||||
function __update(&$Schema, $table = null) {
|
||||
$db =& ConnectionManager::getDataSource($this->Schema->connection);
|
||||
|
||||
$this->out(__('Comparing Database to Schema...', true));
|
||||
$Old = $this->Schema->read();
|
||||
$options = array();
|
||||
if (isset($this->params['f'])) {
|
||||
$options['models'] = false;
|
||||
}
|
||||
$Old = $this->Schema->read($options);
|
||||
$compare = $this->Schema->compare($Old, $Schema);
|
||||
|
||||
$contents = array();
|
||||
|
@ -369,7 +373,7 @@ class SchemaShell extends Shell {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
function __run($contents, $event, $Schema) {
|
||||
function __run($contents, $event, &$Schema) {
|
||||
if (empty($contents)) {
|
||||
$this->err(__('Sql could not be run', true));
|
||||
return;
|
||||
|
|
|
@ -186,6 +186,7 @@ class CakeSchema extends Object {
|
|||
* - 'connection' - the db connection to use
|
||||
* - 'name' - name of the schema
|
||||
* - 'models' - a list of models to use, or false to ignore models
|
||||
*
|
||||
* @param array $options schema object properties
|
||||
* @return array Array indexed by name and tables
|
||||
* @access public
|
||||
|
|
|
@ -47,6 +47,67 @@ Mock::generatePartial(
|
|||
|
||||
Mock::generate('CakeSchema', 'MockSchemaCakeSchema');
|
||||
|
||||
/**
|
||||
* Test for Schema database management
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs
|
||||
*/
|
||||
class SchemaShellTestSchema extends CakeSchema {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'MyApp'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'SchemaShellTest';
|
||||
|
||||
/**
|
||||
* connection property
|
||||
*
|
||||
* @var string 'test_suite'
|
||||
* @access public
|
||||
*/
|
||||
var $connection = 'test_suite';
|
||||
|
||||
/**
|
||||
* comments property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $comments = array(
|
||||
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
||||
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
|
||||
'user_id' => array('type' => 'integer', 'null' => false),
|
||||
'title' => array('type' => 'string', 'null' => false, 'length' => 100),
|
||||
'comment' => array('type' => 'text', 'null' => false, 'default' => null),
|
||||
'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
|
||||
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
||||
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
||||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
|
||||
);
|
||||
|
||||
/**
|
||||
* posts property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $articles = array(
|
||||
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
||||
'user_id' => array('type' => 'integer', 'null' => true, 'default' => ''),
|
||||
'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
|
||||
'body' => array('type' => 'text', 'null' => true, 'default' => null),
|
||||
'summary' => array('type' => 'text', 'null' => true),
|
||||
'published' => array('type' => 'string', 'null' => true, 'default' => 'Y', 'length' => 1),
|
||||
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
||||
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
||||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* SchemaShellTest class
|
||||
*
|
||||
|
@ -279,5 +340,29 @@ class SchemaShellTest extends CakeTestCase {
|
|||
$this->assertFalse(in_array('aros_acos', $sources));
|
||||
}
|
||||
|
||||
/**
|
||||
* test run update with a table arg.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testRunUpdateWithTable() {
|
||||
$this->Shell->params = array(
|
||||
'name' => 'SchemaShellTest',
|
||||
'connection' => 'test_suite',
|
||||
'f' => true
|
||||
);
|
||||
$this->Shell->args = array('update', 'articles');
|
||||
$this->Shell->startup();
|
||||
$this->Shell->setReturnValue('in', 'y');
|
||||
$this->Shell->run();
|
||||
|
||||
$article =& new Model(array('name' => 'Article', 'ds' => 'test_suite'));
|
||||
$fields = $article->schema();
|
||||
$this->assertTrue(isset($fields['summary']));
|
||||
|
||||
$this->_fixtures['core.article']->drop($this->db);
|
||||
$this->_fixtures['core.article']->create($this->db);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue