Context
I have a configuration file in which I precise the MongoDB connection string. I want to test my MongoDB connection, to precise to the devs using my code that their configuration is bad if it's the case.
I use the MongoDB driver.
I did not find anything about tests of the Mongo connection.
Problem
I do:
<?php
$configuration = parse_ini_file("../configs/database.ini");
$mongo = new MongoDB\Client($configuration['resources.mongo.dsn']);
$db = $mongo->stats;
But the only errors thrown are those about bad format of the MongoDB connection string. For example:
with
test_bad_string, aMongoDB\Driver\Exception\InvalidArgumentExceptionis thrownwith
mongodb://127.0.0.1:270(default port for my MongoDB is27017), I don't see any errors
Question
Is there a way to test in PHP the connection to a MongoDB database?