function ConnectionTest::testDestroy
Same name in other branches
- 8.9.x 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 367
Class
- ConnectionTest
- Tests the Connection class.
Namespace
Drupal\Tests\Core\DatabaseCode
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));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.