Alcaeus\MongoDbAdapter\Tests\Mongo\MongoCursorTest::getCursorOptions PHP Method

getCursorOptions() public static method

public static getCursorOptions ( )
    public static function getCursorOptions()
    {
        function getMissingOptionCallback($optionName)
        {
            return function ($value) use($optionName) {
                return is_array($value) && !array_key_exists($optionName, $value);
            };
        }
        function getBasicCheckCallback($expected, $optionName)
        {
            return function ($value) use($expected, $optionName) {
                return is_array($value) && array_key_exists($optionName, $value) && $value[$optionName] == $expected;
            };
        }
        function getModifierCheckCallback($expected, $modifierName)
        {
            return function ($value) use($expected, $modifierName) {
                return is_array($value) && is_array($value['modifiers']) && array_key_exists($modifierName, $value['modifiers']) && $value['modifiers'][$modifierName] == $expected;
            };
        }
        $tests = ['allowPartialResults' => [getBasicCheckCallback(true, 'allowPartialResults'), function (\MongoCursor $cursor) {
            $cursor->partial(true);
        }], 'batchSize' => [getBasicCheckCallback(10, 'batchSize'), function (\MongoCursor $cursor) {
            $cursor->batchSize(10);
        }], 'cursorTypeNonTailable' => [getMissingOptionCallback('cursorType'), function (\MongoCursor $cursor) {
            $cursor->tailable(false)->awaitData(true);
        }], 'cursorTypeTailable' => [getBasicCheckCallback(Find::TAILABLE, 'cursorType'), function (\MongoCursor $cursor) {
            $cursor->tailable(true);
        }], 'cursorTypeTailableAwait' => [getBasicCheckCallback(Find::TAILABLE_AWAIT, 'cursorType'), function (\MongoCursor $cursor) {
            $cursor->tailable(true)->awaitData(true);
        }], 'hint' => [getModifierCheckCallback('index_name', '$hint'), function (\MongoCursor $cursor) {
            $cursor->hint('index_name');
        }], 'limit' => [getBasicCheckCallback(5, 'limit'), function (\MongoCursor $cursor) {
            $cursor->limit(5);
        }], 'maxTimeMS' => [getBasicCheckCallback(100, 'maxTimeMS'), function (\MongoCursor $cursor) {
            $cursor->maxTimeMS(100);
        }], 'noCursorTimeout' => [getBasicCheckCallback(true, 'noCursorTimeout'), function (\MongoCursor $cursor) {
            $cursor->immortal(true);
        }], 'slaveOkay' => [getBasicCheckCallback(new ReadPreference(ReadPreference::RP_SECONDARY_PREFERRED), 'readPreference'), function (\MongoCursor $cursor) {
            $cursor->slaveOkay(true);
        }], 'slaveOkayWithReadPreferenceSet' => [getBasicCheckCallback(new ReadPreference(ReadPreference::RP_SECONDARY), 'readPreference'), function (\MongoCursor $cursor) {
            $cursor->setReadPreference(\MongoClient::RP_SECONDARY)->slaveOkay(true);
        }], 'projectionDefaultFields' => [getBasicCheckCallback(new BSONDocument(['_id' => false, 'foo' => true]), 'projection')], 'projectionDifferentFields' => [getBasicCheckCallback(new BSONDocument(['_id' => false, 'foo' => true, 'bar' => true]), 'projection'), function (\MongoCursor $cursor) {
            $cursor->fields(['_id' => false, 'foo' => true, 'bar' => true]);
        }], 'readPreferencePrimary' => [getBasicCheckCallback(new ReadPreference(ReadPreference::RP_PRIMARY), 'readPreference'), function (\MongoCursor $cursor) {
            $cursor->setReadPreference(\MongoClient::RP_PRIMARY);
        }], 'skip' => [getBasicCheckCallback(5, 'skip'), function (\MongoCursor $cursor) {
            $cursor->skip(5);
        }], 'sort' => [getBasicCheckCallback(['foo' => -1], 'sort'), function (\MongoCursor $cursor) {
            $cursor->sort(['foo' => -1]);
        }]];
        return $tests;
    }