You are here

public function ConnectionTest::testDestroy in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Database/ConnectionTest.php \Drupal\Tests\Core\Database\ConnectionTest::testDestroy()

Tests Connection::destroy().

@group legacy

File

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

Class

ConnectionTest
Tests the Connection class.

Namespace

Drupal\Tests\Core\Database

Code

public function testDestroy() {
  $this
    ->expectDeprecation('Drupal\\Core\\Database\\Connection::destroy() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Move custom database destruction logic to __destruct(). See https://www.drupal.org/node/3142866');
  $mock_pdo = $this
    ->createMock('Drupal\\Tests\\Core\\Database\\Stub\\StubPDO');

  // Mocking StubConnection gives us access to the $schema attribute.
  $connection = new StubConnection($mock_pdo, [
    'namespace' => 'Drupal\\Tests\\Core\\Database\\Stub\\Driver',
  ]);

  // Generate a schema object in order to verify that we've NULLed it later.
  $this
    ->assertInstanceOf('Drupal\\Tests\\Core\\Database\\Stub\\Driver\\Schema', $connection
    ->schema());
  $connection
    ->destroy();
  $reflected_schema = (new \ReflectionObject($connection))
    ->getProperty('schema');
  $reflected_schema
    ->setAccessible(TRUE);
  $this
    ->assertNull($reflected_schema
    ->getValue($connection));
}