SchemaTest.php

Same filename in this branch
  1. 11.x core/modules/mysql/tests/src/Kernel/mysql/SchemaTest.php
  2. 11.x core/modules/pgsql/tests/src/Unit/SchemaTest.php
  3. 11.x core/modules/pgsql/tests/src/Kernel/pgsql/SchemaTest.php
Same filename in other branches
  1. 9 core/modules/mysql/tests/src/Kernel/mysql/SchemaTest.php
  2. 9 core/modules/pgsql/tests/src/Unit/SchemaTest.php
  3. 9 core/modules/pgsql/tests/src/Kernel/pgsql/SchemaTest.php
  4. 9 core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
  5. 8.9.x core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
  6. 10 core/modules/sqlite/tests/src/Kernel/sqlite/SchemaTest.php
  7. 10 core/modules/mysql/tests/src/Kernel/mysql/SchemaTest.php
  8. 10 core/modules/pgsql/tests/src/Unit/SchemaTest.php
  9. 10 core/modules/pgsql/tests/src/Kernel/pgsql/SchemaTest.php

Namespace

Drupal\Tests\sqlite\Kernel\sqlite

File

core/modules/sqlite/tests/src/Kernel/sqlite/SchemaTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\sqlite\Kernel\sqlite;

use Drupal\KernelTests\Core\Database\DriverSpecificSchemaTestBase;

/**
 * Tests schema API for the SQLite driver.
 *
 * @group Database
 */
class SchemaTest extends DriverSpecificSchemaTestBase {
    
    /**
     * {@inheritdoc}
     */
    public function checkSchemaComment(string $description, string $table, ?string $column = NULL) : void {
        // The sqlite driver schema does not support fetching table/column
        // comments.
    }
    
    /**
     * {@inheritdoc}
     */
    protected function tryInsertExpectsIntegrityConstraintViolationException(string $tableName) : void {
        // Sqlite does not throw an IntegrityConstraintViolationException here.
    }
    
    /**
     * {@inheritdoc}
     */
    public function testTableWithSpecificDataType() : void {
        $table_specification = [
            'description' => 'Schema table description.',
            'fields' => [
                'timestamp' => [
                    'sqlite_type' => 'datetime',
                    'not null' => FALSE,
                    'default' => NULL,
                ],
            ],
        ];
        $this->schema
            ->createTable('test_timestamp', $table_specification);
        $this->assertTrue($this->schema
            ->tableExists('test_timestamp'));
    }
    
    /**
     * @covers \Drupal\sqlite\Driver\Database\sqlite\Schema::introspectIndexSchema
     */
    public function testIntrospectIndexSchema() : void {
        $table_specification = [
            'fields' => [
                'id' => [
                    'type' => 'int',
                    'not null' => TRUE,
                    'default' => 0,
                ],
                'test_field_1' => [
                    'type' => 'int',
                    'not null' => TRUE,
                    'default' => 0,
                ],
                'test_field_2' => [
                    'type' => 'int',
                    'default' => 0,
                ],
                'test_field_3' => [
                    'type' => 'int',
                    'default' => 0,
                ],
                'test_field_4' => [
                    'type' => 'int',
                    'default' => 0,
                ],
                'test_field_5' => [
                    'type' => 'int',
                    'default' => 0,
                ],
            ],
            'primary key' => [
                'id',
                'test_field_1',
            ],
            'unique keys' => [
                'test_field_2' => [
                    'test_field_2',
                ],
                'test_field_3_test_field_4' => [
                    'test_field_3',
                    'test_field_4',
                ],
            ],
            'indexes' => [
                'test_field_4' => [
                    'test_field_4',
                ],
                'test_field_4_test_field_5' => [
                    'test_field_4',
                    'test_field_5',
                ],
            ],
        ];
        $table_name = strtolower($this->getRandomGenerator()
            ->name());
        $this->schema
            ->createTable($table_name, $table_specification);
        unset($table_specification['fields']);
        $introspect_index_schema = new \ReflectionMethod(get_class($this->schema), 'introspectIndexSchema');
        $index_schema = $introspect_index_schema->invoke($this->schema, $table_name);
        $this->assertEquals($table_specification, $index_schema);
    }

}

Classes

Title Deprecated Summary
SchemaTest Tests schema API for the SQLite driver.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.