Sokil\Mongo\CursorTest::testHint PHP Method

testHint() public method

public testHint ( )
    public function testHint()
    {
        // create index
        $this->collection->ensureIndex(array('a' => 1));
        $this->collection->ensureIndex(array('a' => 1, 'b' => 1));
        // add documents
        $this->collection->insert(array('a' => 1))->insert(array('a' => 1, 'b' => 1));
        // without hint
        $explainWithoutHint = $this->collection->find()->where('a', 1)->explain();
        // with hint
        $explainWithHint = $this->collection->find()->hint(array('a' => 1, 'b' => 1))->where('a', 1)->explain();
        $currentVersion = $this->collection->getDatabase()->getClient()->getDbVersion();
        if (version_compare($currentVersion, '3', '<')) {
            $this->assertEquals('BtreeCursor a_1', $explainWithoutHint['cursor']);
            $this->assertEquals('BtreeCursor a_1_b_1', $explainWithHint['cursor']);
        } else {
            $this->assertEquals('a_1', $explainWithoutHint['queryPlanner']['winningPlan']['inputStage']['indexName']);
            $this->assertEquals('a_1_b_1', $explainWithHint['queryPlanner']['winningPlan']['inputStage']['indexName']);
        }
    }