function SchemaTest::testComputedConstraintName

Same name and namespace in other branches
  1. 9 core/modules/pgsql/tests/src/Unit/SchemaTest.php \Drupal\Tests\pgsql\Unit\SchemaTest::testComputedConstraintName()
  2. 10 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 <a href="/api/drupal/core%21modules%21pgsql%21src%21Driver%21Database%21pgsql%21Schema.php/class/Schema/11.x" 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) : 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.