function SchemaDefinitionTest::testSchemaMethods
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/Core/Database/SchemaDefinitionTest.php \Drupal\Tests\Core\Database\SchemaDefinitionTest::testSchemaMethods()
Tests Schema.
File
-
core/
tests/ Drupal/ Tests/ Core/ Database/ SchemaDefinitionTest.php, line 36
Class
- SchemaDefinitionTest
- Tests SchemaDefinition Column object validations.
Namespace
Drupal\Tests\Core\DatabaseCode
public function testSchemaMethods() : void {
$schemaDefinition = new Schema(type: SchemaDefinitionType::Test, name: 'test_foo_bar', tables: [
new Table(name: 'foo', description: 'Foo table for the database unit tests.', columns: [
Column::serial(name: 'id'),
], primaryKey: new PrimaryKey([
'id',
])),
new Table(name: 'bar', description: 'Bar table for the database unit tests.', columns: [
Column::serial(name: 'id'),
], primaryKey: new PrimaryKey([
'id',
])),
]);
// Check ::tableNames().
$this->assertSame([
'foo',
'bar',
], $schemaDefinition->tableNames());
// Check ::getTableDefinition().
$tableDefinition = $schemaDefinition->getTableDefinition('foo');
$this->assertInstanceOf(Table::class, $tableDefinition);
$this->assertSame('foo', $tableDefinition->name);
$this->assertSame('Foo table for the database unit tests.', $tableDefinition->description);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.