function ConnectionTest::testPrefixRoundTrip

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Database/ConnectionTest.php \Drupal\Tests\Core\Database\ConnectionTest::testPrefixRoundTrip()
  2. 8.9.x core/tests/Drupal/Tests/Core/Database/ConnectionTest.php \Drupal\Tests\Core\Database\ConnectionTest::testPrefixRoundTrip()
  3. 11.x core/tests/Drupal/Tests/Core/Database/ConnectionTest.php \Drupal\Tests\Core\Database\ConnectionTest::testPrefixRoundTrip()

Exercise setPrefix() and tablePrefix().

@dataProvider providerPrefixRoundTrip

File

core/tests/Drupal/Tests/Core/Database/ConnectionTest.php, line 54

Class

ConnectionTest
Tests the Connection class.

Namespace

Drupal\Tests\Core\Database

Code

public function testPrefixRoundTrip($expected, $prefix_info) : void {
  $mock_pdo = $this->createMock('Drupal\\Tests\\Core\\Database\\Stub\\StubPDO');
  $connection = new StubConnection($mock_pdo, []);
  // setPrefix() is protected, so we make it accessible with reflection.
  $reflection = new \ReflectionClass('Drupal\\Tests\\Core\\Database\\Stub\\StubConnection');
  $set_prefix = $reflection->getMethod('setPrefix');
  // Set the prefix data.
  $set_prefix->invokeArgs($connection, [
    $prefix_info,
  ]);
  // Check the round-trip.
  foreach ($expected as $table => $prefix) {
    $this->assertEquals($prefix, $connection->getPrefix());
  }
}

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