Problem/Motivation
Unnecessary double call to db_drop_field on a test.
Proposed resolution
Remove it.
Remaining tasks
Reroll for D8.
User interface changes
None.
API changes
None.
Original report by aaaristo
protected function assertFieldAdditionRemoval($field_spec) {
global $oracle_debug;
// Try creating the field on a new table.
$table_name = 'test_table_' . ($this->counter++);
$table_spec = array(
'fields' => array(
'serial_column' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
'test_field' => $field_spec,
),
'primary key' => array('serial_column'),
);
db_create_table($table_name, $table_spec);
$this->pass(t('Table %table created.', array('%table' => $table_name)));
// Check the characteristics of the field.
$this->assertFieldCharacteristics($table_name, 'test_field', $field_spec);
// Clean-up.
db_drop_table($table_name);
// Try adding a field to an existing table.
$table_name = 'test_table_' . ($this->counter++);
$table_spec = array(
'fields' => array(
'serial_column' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
),
'primary key' => array('serial_column'),
);
db_create_table($table_name, $table_spec);
$this->pass(t('Table %table created.', array('%table' => $table_name)));
// Insert some rows to the table to test the handling of initial values.
for ($i = 0; $i < 3; $i++) {
db_insert($table_name)
->useDefaults(array('serial_column'))
->execute();
}
db_add_field($table_name, 'test_field', $field_spec);
$this->pass(t('Column %column created.', array('%column' => 'test_field')));
// Check the characteristics of the field.
$this->assertFieldCharacteristics($table_name, 'test_field', $field_spec);
// Clean-up.
db_drop_field($table_name, 'test_field'); <------------------------------ this is already done by assertFieldCharacteristics!!
db_drop_table($table_name);
}
should we remove it?
Comments
Comment #1
damien tournoud commentedWe should remove it, but from assertFieldCharacteristics().
Also, make sure that your implementation of dropField() satisfies the contract: it should return false without an exception if the field does not exist.
Comment #2
aaaristo commentedok, i've attached a patch for this.
Comment #3
aaaristo commentedComment #4
marvil07 commentedPlease move the change to core/modules/system/src/Tests/Database/SchemaTest.php, extra line is still there
Also I took a look to the different implementations of dropField() and they seem to be checking correctly if field exists first.
Comment #5
mrjmd commentedPatch attached against 8.0.x.
Comment #6
marvil07 commentedThanks
Comment #7
catchCommitted/pushed to 8.0.x, thanks!