Alcaeus\MongoDbAdapter\Tests\Mongo\MongoCollectionTest::testEnsureIndex PHP Method

testEnsureIndex() public method

public testEnsureIndex ( )
    public function testEnsureIndex()
    {
        $expected = ['createdCollectionAutomatically' => true, 'numIndexesBefore' => 1, 'numIndexesAfter' => 2, 'ok' => 1.0];
        $collection = $this->getCollection();
        $this->assertEquals($expected, $collection->ensureIndex(['bar' => 1], ['unique' => true]));
        $newCollection = $this->getCheckDatabase()->selectCollection('test');
        $indexes = iterator_to_array($newCollection->listIndexes());
        $this->assertCount(2, $indexes);
        $index = $indexes[1];
        $this->assertSame(['bar' => 1], $index->getKey());
        $this->assertTrue($index->isUnique());
        $this->assertSame('mongo-php-adapter.test', $index->getNamespace());
    }
MongoCollectionTest