Changes building of mongodb and conditions & fixes #2868

First added some tests - which failed: https://travis-ci.org/dirx/yii2/builds/21743388
Then added fix and minor improvement on test - looks good: https://travis-ci.org/dirx/yii2/builds/21748983

Hope this helps.