コード例 #1
0
 public function testListIndexesForNonexistentCollection()
 {
     $operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName());
     $operation->execute($this->getPrimaryServer());
     $operation = new ListIndexes($this->getDatabaseName(), $this->getCollectionName());
     $indexes = $operation->execute($this->getPrimaryServer());
     $this->assertCount(0, $indexes);
 }
コード例 #2
0
 /**
  * Asserts that an index with the given name exists for the collection.
  *
  * An optional $callback may be provided, which should take an IndexInfo
  * argument as its first and only parameter. If an IndexInfo matching the
  * given name is found, it will be passed to the callback, which may perform
  * additional assertions.
  *
  * @param callable $callback
  */
 private function assertIndexExists($indexName, $callback = null)
 {
     if ($callback !== null && !is_callable($callback)) {
         throw new InvalidArgumentException('$callback is not a callable');
     }
     $operation = new ListIndexes($this->getDatabaseName(), $this->getCollectionName());
     $indexes = $operation->execute($this->getPrimaryServer());
     $foundIndex = null;
     foreach ($indexes as $index) {
         if ($index->getName() === $indexName) {
             $foundIndex = $index;
             break;
         }
     }
     $this->assertNotNull($foundIndex, sprintf('Found %s index for the collection', $indexName));
     if ($callback !== null) {
         call_user_func($callback, $foundIndex);
     }
 }
コード例 #3
0
 /**
  * Returns information for all indexes for the collection.
  *
  * @see ListIndexes::__construct() for supported options
  * @return IndexInfoIterator
  */
 public function listIndexes(array $options = [])
 {
     $operation = new ListIndexes($this->databaseName, $this->collectionName, $options);
     $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
     return $operation->execute($server);
 }