You are here

protected function SqlImportTest::getKvCollectionNames in MongoDB 8.2

Test helper: list the KV(E|P) collections.

Return value

array The sorted array of the (unprefixed) KV collections names.

Throws

\Exception

1 call to SqlImportTest::getKvCollectionNames()
SqlImportTest::testImportActual in modules/mongodb_storage/tests/src/Kernel/SqlImportTest.php
@covers ::getCollections @covers ::importPersistent @covers ::importExpirable

File

modules/mongodb_storage/tests/src/Kernel/SqlImportTest.php, line 86

Class

SqlImportTest
Tests the import for the commands.mongodb.storage.import_keyvalue command.

Namespace

Drupal\Tests\mongodb_storage\Kernel

Code

protected function getKvCollectionNames(string $prefix) : array {
  $cursor = $this->container
    ->get(MongoDb::SERVICE_DB_FACTORY)
    ->get(KeyValueFactory::DB_KEYVALUE)
    ->listCollections();
  $result = [];
  $len = strlen($prefix);
  foreach ($cursor as $collection) {
    if (strpos($name = $collection
      ->getName(), $prefix) === 0) {
      $result[] = substr($name, $len);
    }
  }
  sort($result);
  return $result;
}