DominionEnterprises\Mongo\Queue::ensureCountIndex PHP Method

ensureCountIndex() public method

Is a no-op if the generated index is a prefix of an existing one. If you have a similar ensureGetIndex call, call it first.
public ensureCountIndex ( array $fields, boolean $includeRunning ) : void
$fields array fields in count() call to index in same format as \MongoDB\Collection::createIndex()
$includeRunning boolean whether to include the running field in the index
return void
    public function ensureCountIndex(array $fields, $includeRunning)
    {
        if (!is_bool($includeRunning)) {
            throw new \InvalidArgumentException('$includeRunning was not a boolean');
        }
        $completeFields = [];
        if ($includeRunning) {
            $completeFields['running'] = 1;
        }
        self::verifySort($fields, 'fields', $completeFields);
        $this->ensureIndex($completeFields);
    }

Usage Example

コード例 #1
0
 /**
  * Verifies the behaviour of the Queue when it cannot create an index after 5 attempts.
  *
  * @test
  * @covers ::ensureGetIndex
  * @expectedException \Exception
  * @expectedExceptionMessage couldnt create index after 5 attempts
  */
 public function ensureIndexCannotBeCreatedAfterFiveAttempts()
 {
     $mockCollection = $this->getMockBuilder('\\MongoDB\\Collection')->disableOriginalConstructor()->getMock();
     $mockCollection->method('listIndexes')->willReturn([]);
     $queue = new Queue($mockCollection);
     $queue->ensureCountIndex(['type' => 1], false);
 }