function SchemaTest::testComputedConstraintName

Same name in other branches
  1. 9 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 30

Class

SchemaTest
@coversDefaultClass \Drupal\pgsql\Driver\Database\pgsql\Schema @group Database

Namespace

Drupal\Tests\pgsql\Unit

Code

public function testComputedConstraintName($table_name, $name, $expected) : void {
    $max_identifier_length = 63;
    $connection = $this->prophesize('\\Drupal\\pgsql\\Driver\\Database\\pgsql\\Connection');
    $connection->getConnectionOptions()
        ->willReturn([]);
    $connection->getPrefix()
        ->willReturn('');
    $statement = $this->prophesize('\\Drupal\\Core\\Database\\StatementInterface');
    $statement->fetchField()
        ->willReturn($max_identifier_length);
    $connection->query('SHOW max_identifier_length')
        ->willReturn($statement->reveal());
    $connection->query(Argument::containingString($expected))
        ->willReturn($this->prophesize('\\Drupal\\Core\\Database\\StatementInterface')
        ->reveal())
        ->shouldBeCalled();
    $schema = new Schema($connection->reveal());
    $schema->constraintExists($table_name, $name);
}

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