SchemaTest.php

Same filename in this branch
  1. 11.x core/modules/sqlite/tests/src/Kernel/sqlite/SchemaTest.php
  2. 11.x core/modules/mysql/tests/src/Kernel/mysql/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\pgsql\Unit

File

core/modules/pgsql/tests/src/Unit/SchemaTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\pgsql\Unit;

use Drupal\pgsql\Driver\Database\pgsql\Schema;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;

/**
 * @coversDefaultClass \Drupal\pgsql\Driver\Database\pgsql\Schema
 * @group Database
 */
class SchemaTest extends UnitTestCase {
    
    /**
     * Tests whether the actual constraint name is correctly computed.
     *
     * @param string $table_name
     *   The table name the constrained column belongs to.
     * @param string $name
     *   The constraint name.
     * @param string $expected
     *   The expected computed constraint name.
     *
     * @covers ::constraintExists
     * @dataProvider providerComputedConstraintName
     */
    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);
    }
    
    /**
     * Data provider for ::testComputedConstraintName().
     */
    public static function providerComputedConstraintName() {
        return [
            [
                'user_field_data',
                'pkey',
                'user_field_data____pkey',
            ],
            [
                'user_field_data',
                'name__key',
                'user_field_data__name__key',
            ],
            [
                'user_field_data',
                'a_very_very_very_very_super_long_field_name__key',
                'drupal_WW_a8TlbZ3UQi20UTtRlJFaIeSa6FEtQS5h4NRA3UeU_key',
            ],
        ];
    }

}

Classes

Title Deprecated Summary
SchemaTest @coversDefaultClass \Drupal\pgsql\Driver\Database\pgsql\Schema @group Database

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