public function MongoCollectionFactory::__destruct in MongoDB 8
Remove test collections when a test run ends.
The class is held alive by the container of the test.
File
- src/
MongoCollectionFactory.php, line 180 - Definition of Drupal\mongodb\MongodbBundle.
Class
- MongoCollectionFactory
- Creates mongo collections based on settings.
Namespace
Drupal\mongodbCode
public function __destruct() {
if ($this->testDatabasePrefix && !drupal_valid_test_ua()) {
foreach ($this->serverInfo as $server) {
$connection_string = $server['server'];
if (isset($this->clients[$connection_string])) {
/** @var \MongoDb $db */
$db = $this->clients[$connection_string]
->selectDB($server['db']);
foreach ($db
->getCollectionNames() as $collection_name) {
if (substr($collection_name, 0, 16) == $this->testDatabasePrefix) {
$db->{$collection_name}
->drop();
}
}
}
}
}
}