Developers who would like to contribute to the library will need to clone it and initialize the project dependencies with Composer:
$ git clone https://github.com/mongodb/mongo-php-library.git
$ cd mongo-php-library
$ composer update
In addition to installing project dependencies, Composer will check that the required extension version is installed. Directions for installing the extension may be found here.
Installation directions for Composer may be found in its Getting Started guide.
The library's test suite uses PHPUnit, which is installed through the PHPUnit Bridge dependency by Composer.
The test suite may be executed with:
$ composer run testThe phpunit.xml.dist file is used as the default configuration file for the
test suite. In addition to various PHPUnit options, it defines environment
variables such as MONGODB_URI and MONGODB_DATABASE. You may customize
this configuration by creating your own phpunit.xml file based on the
phpunit.xml.dist file we provide. To run the tests in serverless mode, set the
MONGODB_IS_SERVERLESS environment variable to on.
To run tests against a cluster that requires authentication, either include the
credentials in the connection string (i.e. MONGODB_URI) or set the
MONGODB_USERNAME and MONGODB_PASSWORD environment variables accordingly.
Note that MONGODB_USERNAME and MONGODB_PASSWORD will override any
credentials present in the connection string.
By default, the simple-phpunit binary chooses the correct PHPUnit version for
the PHP version you are running. To run tests against a specific PHPUnit
version, use the SYMFONY_PHPUNIT_VERSION environment variable:
$ SYMFONY_PHPUNIT_VERSION=8.5 vendor/bin/simple-phpunitThe test suite references the following environment variables:
MONGODB_DATABASE: Default database to use in tests. Defaults tophplib_test.MONGODB_PASSWORD: If specified, this value will be appended as thepasswordURI option for clients constructed by the test suite, which will override any credentials in the connection string itself.MONGODB_URI: Connection string. Defaults tomongodb://127.0.0.1/, which assumes a MongoDB server is listening on localhost port 27017.MONGODB_USERNAME: If specified, this value will be appended as theusernameURI option for clients constructed by the test suite, which will override any credentials in the connection string itself.
The following environment variable is used for stable API testing:
API_VERSION: If defined, this value will be used to construct aMongoDB\Driver\ServerApi, which will then be specified as theserverApidriver option for clients created by the test suite.
The following environment variable is used for serverless testing:
MONGODB_IS_SERVERLESS: Specify a true boolean string (see:FILTER_VALIDATE_BOOLEAN) ifMONGODB_URIpoints to a serverless instance. Defaults to false.
The following environment variables are used for load balancer testing:
MONGODB_SINGLE_MONGOS_LB_URI: Connection string to a load balancer backed by a single mongos host.MONGODB_MULTI_MONGOS_LB_URI: Connection string to a load balancer backed by multiple mongos hosts.
The following environment variables are used for CSFLE testing:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_TEMP_ACCESS_KEY_IDAWS_TEMP_SECRET_ACCESS_KEYAWS_TEMP_SESSION_TOKENAZURE_TENANT_IDAZURE_CLIENT_IDAZURE_CLIENT_SECRETCRYPT_SHARED_LIB_PATH: If defined, this value will be used to set thecryptSharedLibPathautoEncryption driver option for clients created by the test suite.GCP_EMAILGCP_PRIVATE_KEYKMIP_ENDPOINTKMS_ENDPOINT_EXPIREDKMS_ENDPOINT_WRONG_HOSTKMS_ENDPOINT_REQUIRE_CLIENT_CERTKMS_TLS_CA_FILEKMS_TLS_CERTIFICATE_KEY_FILE
Before submitting a pull request, please ensure that your code adheres to the coding standards and passes static analysis checks.
$ composer run checksThe library's code is checked using PHP_CodeSniffer,
which is installed as a development dependency by Composer. To check the code
for style errors, run the phpcs binary:
$ vendor/bin/phpcsTo automatically fix all fixable errors, use the phpcbf binary:
$ vendor/bin/phpcbfThe library uses psalm to run static analysis on the code
and ensure an additional level of type safety. New code is expected to adhere
to level 1, with a baseline covering existing issues. To run static analysis
checks, run the psalm binary:
$ vendor/bin/psalmTo remove fixed errors from the baseline, you can use the update-baseline
command-line argument:
$ vendor/bin/psalm --update-baselineNote that this will not add new errors to the baseline. New errors should be
fixed instead of being added to the technical debt, but in case this isn't
possible it can be added to the baseline using set-baseline:
$ vendor/bin/psalm --set-baseline=psalm-baseline.xmlThe library uses rector to refactor the code for new features.
To run automatic refactoring, use the rector command:
$ vendor/bin/rectorNew rules can be added to the rector.php configuration file.
Documentation for the library is maintained by the MongoDB docs team and is kept in the mongodb/docs-php-library repository.
The releases are created by the maintainers of the library. The process is documented in the RELEASING.md file.