class PostgresqlSchemaTest in Drupal 8
@coversDefaultClass \Drupal\Core\Database\Driver\pgsql\Schema @group Database
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\Core\Database\Driver\pgsql\PostgresqlSchemaTest
Expanded class hierarchy of PostgresqlSchemaTest
File
- core/
tests/ Drupal/ Tests/ Core/ Database/ Driver/ pgsql/ PostgresqlSchemaTest.php, line 12
Namespace
Drupal\Tests\Core\Database\Driver\pgsqlView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
PostgresqlSchemaTest:: |
protected | property | The PostgreSql DB connection. | |
PostgresqlSchemaTest:: |
public | function | Data provider for ::testComputedConstraintName(). | |
PostgresqlSchemaTest:: |
protected | function |
Overrides UnitTestCase:: |
|
PostgresqlSchemaTest:: |
public | function | Tests whether the actual constraint name is correctly computed. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |