Download the PHP package helmich/mongomock without Composer

On this page you can find all versions of the php package helmich/mongomock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mongomock

MongoDB mock classes

Unit tests

Author and license

Martin Helmich
This library is MIT-licenced.

Synopsis and motivation

This class contains implementations of the MongoDB\Collection and MongoDB\Database classes (not to be confused with the Mongo\Collection class from the deprecated mongo extension) that can store, modify and filter documents in memory, together with a set of (optional) PHPUnit assertions.

I wrote this library because I wanted to unit-test a library that used MongoDB collections intensively and felt that mocking the MongoDB\Collection class using PHPUnit's built-in mock builders was too restrictive.

Note: Currently, this implementation contains only a subset of the actual MongoDB collection API. I've only implemented the parts of the API that I needed for my use case. If you need additional functionality, feel free to open an issue, or (better yet) a pull request.

Installation

$ composer require --dev helmich/mongomock

Compatibility

There are several release branches of this library, each of these being compatible with different releases of PHPUnit and PHP. The following table should give an easy overview:

"Mongomock" version PHPUnit 4 PHPUnit 5 PHPUnit 6 PHPUnit 7 PHPUnit 8 PHPUnit 9
v1 (branch v1), unsupported :no_entry_sign: :white_check_mark: :no_entry_sign: :no_entry_sign: :no_entry_sign: :no_entry_sign:
v2 (branch master) :no_entry_sign: :no_entry_sign: :white_check_mark: :white_check_mark: :white_check_mark: :white_check_mark:

When you are using composer require and have already declared a dependency to phpunit/phpunit in your composer.json file, Composer should pick latest compatible version automatically.

Usage

You can use this library exactly as you'd use the MongoDB\Collection or MongoDB\Database classes (in theory, at least -- remember, this package is not API-complete):

Differences

In some aspects, the MongoDB\Collection's API was extended to allow for better testability:

  1. Filter operands may contain callback functions that are applied to document properties:

  2. Filter operands may contain PHPUnit constraints (meaning instances of the PHPUnit_Framework_Constraint class). You can easily build these using the factory functions in the PHPUnit_Framework_Assert class.

Testing

To run the tests (anywhere with a running Docker installation):


All versions of mongomock with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1.0 || ^8.0
ext-mongodb Version *
mongodb/mongodb Version ^1.0
phpunit/phpunit Version >=6.0,<10.0
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package helmich/mongomock contains the following files

Loading the files please wait ....