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?

CommentFileSizeAuthor
#5 1052854-5.patch556 bytesmrjmd
#2 1052854.patch379 bytesaaaristo

Comments

damien tournoud’s picture

We 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.

aaaristo’s picture

StatusFileSize
new379 bytes

ok, i've attached a patch for this.

aaaristo’s picture

Status: Active » Needs review
marvil07’s picture

Version: 7.0 » 8.0.x-dev
Issue summary: View changes
Status: Needs review » Needs work

Please 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.

mrjmd’s picture

Component: simpletest.module » system.module
Status: Needs work » Needs review
StatusFileSize
new556 bytes

Patch attached against 8.0.x.

marvil07’s picture

Status: Needs review » Reviewed & tested by the community

Thanks

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.0.x, thanks!

  • catch committed a305f77 on 8.0.x
    Issue #1052854 by aaaristo, mrjmd: double db_drop_field in schema.test
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.