public function DatabaseLegacyTest::testDbAddField in Drupal 8
Tests deprecation of the db_add_field() function.
@expectedDeprecation db_add_field() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addField() on it. For example, $injected_database->schema()->addField($table, $field, $spec, $keys_new). See https://www.drupal.org/node/2993033
File
- core/
tests/ Drupal/ KernelTests/ Core/ Database/ DatabaseLegacyTest.php, line 236
Class
- DatabaseLegacyTest
- Deprecation tests cases for the database layer.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testDbAddField() {
$this
->assertFalse($this->connection
->schema()
->fieldExists('test', 'anint'));
db_add_field('test', 'anint', [
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Added int column.',
]);
$this
->assertTrue($this->connection
->schema()
->fieldExists('test', 'anint'));
}