function SchemaTest::testComputedConstraintName

Same name and namespace in other branches
  1. 10 core/modules/pgsql/tests/src/Unit/SchemaTest.php \Drupal\Tests\pgsql\Unit\SchemaTest::testComputedConstraintName()
  2. 11.x core/modules/pgsql/tests/src/Unit/SchemaTest.php \Drupal\Tests\pgsql\Unit\SchemaTest::testComputedConstraintName()

Tests whether the actual constraint name is correctly computed.

@covers ::constraintExists @dataProvider providerComputedConstraintName

Parameters

string $table_name: The table name the constrained column belongs to.

string $name: The constraint name.

string $expected: The expected computed constraint name.

File

core/modules/pgsql/tests/src/Unit/SchemaTest.php, line 47

Class

SchemaTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21pgsql%21src%21Driver%21Database%21pgsql%21Schema.php/class/Schema/9" title="PostgreSQL implementation of \Drupal\Core\Database\Schema." class="local">\Drupal\pgsql\Driver\Database\pgsql\Schema</a> @group Database

Namespace

Drupal\Tests\pgsql\Unit

Code

public function testComputedConstraintName($table_name, $name, $expected) {
    $max_identifier_length = 63;
    $schema = new Schema($this->connection);
    $statement = $this->createMock('\\Drupal\\Core\\Database\\StatementInterface');
    $statement->expects($this->any())
        ->method('fetchField')
        ->willReturn($max_identifier_length);
    $this->connection
        ->expects($this->exactly(2))
        ->method('query')
        ->withConsecutive([
        $this->anything(),
    ], [
        "SELECT 1 FROM pg_constraint WHERE conname = '{$expected}'",
    ])
        ->willReturnOnConsecutiveCalls($statement, $this->createMock('\\Drupal\\Core\\Database\\StatementInterface'));
    $schema->constraintExists($table_name, $name);
}

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