You are here

class PostgresqlSchemaTest in Drupal 8

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

Hierarchy

Expanded class hierarchy of PostgresqlSchemaTest

File

core/tests/Drupal/Tests/Core/Database/Driver/pgsql/PostgresqlSchemaTest.php, line 12

Namespace

Drupal\Tests\Core\Database\Driver\pgsql
View source
class PostgresqlSchemaTest extends UnitTestCase {

  /**
   * The PostgreSql DB connection.
   *
   * @var \PHPUnit\Framework\MockObject\MockObject|\Drupal\Core\Database\Driver\pgsql\Connection
   */
  protected $connection;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->connection = $this
      ->getMockBuilder('\\Drupal\\Core\\Database\\Driver\\pgsql\\Connection')
      ->disableOriginalConstructor()
      ->getMock();
  }

  /**
   * 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) {
    $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
      ->any())
      ->method('query')
      ->willReturn($statement);
    $this->connection
      ->expects($this
      ->at(2))
      ->method('query')
      ->with("SELECT 1 FROM pg_constraint WHERE conname = '{$expected}'")
      ->willReturn($this
      ->createMock('\\Drupal\\Core\\Database\\StatementInterface'));
    $schema
      ->constraintExists($table_name, $name);
  }

  /**
   * Data provider for ::testComputedConstraintName().
   */
  public 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_veeeery_veery_very_super_long_field_name__key',
        'drupal_BGGYAXgbqlAF1rMOyFTdZGj9zIMXZtSvEjMAKZ9wGIk_key',
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
PostgresqlSchemaTest::$connection protected property The PostgreSql DB connection.
PostgresqlSchemaTest::providerComputedConstraintName public function Data provider for ::testComputedConstraintName().
PostgresqlSchemaTest::setUp protected function Overrides UnitTestCase::setUp
PostgresqlSchemaTest::testComputedConstraintName public function Tests whether the actual constraint name is correctly computed.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.