Download the PHP package michaelmoussa/doctrine-qbmocker without Composer

On this page you can find all versions of the php package michaelmoussa/doctrine-qbmocker. 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 doctrine-qbmocker

Build Status Coverage Status Latest Stable Version

Doctrine QueryBuilderMocker

What's this?

A tool for easy mocking of Doctrine QueryBuilder objects to facilitate unit testing.

Example

Suppose you have a collection of user accounts with documents looking like this:

You have a User service class with a method that returns all names and e-mail address of users in a particular country, sorted by lastName, firstName:

Simple enough. Now how do we test it?

We could create a test database, add a few test records, then run the method to see if it retrieves the right data, but that's not ideal.

  1. Connecting to a database in a test is relatively slow. Too many such tests in a test suite can cause it to really drag.
  2. It only tests that you're getting the expected data back - not that your method is retrieving it correctly.
    • What if someone accidentally deletes the ->field('country')->equals($country)? Or changes it to ->gte($country)? Or removes the ->sort('lastName', 'firstName')?
    • Depending on what test records you created and the order in which you created them, you may still get the expected results back even though your method is not retrieving them the way you'd expect. Your test would still pass, but the code would be wrong.

The better way to test this is to mock the expected method calls and make sure the Query Builder is being used correctly.

But that ends up being pretty messy... take a look:

Imagine a unit test class filled with dozens of those! Surely we can do better. How about this?

Short and concise! Notice that it looks almost identical to the calls being made in the actual service class: The only difference is that execute() accepts a parameter, which ends up becoming the value that the mocked call to execute() will return. Mocking a method's usage of the Query Builder (or vice-versa, for those of us who TDD) is as simple as copying-and-pasting.

Prefer MySQL? This library supports mocking Doctrine ORM query builders as well. Just use MMoussa\Doctrine\Test\ORM\QueryBuilderMocker instead of MMoussa\Doctrine\Test\ODM\MongoDB\QueryBuilderMocker!

Installation

The only supported method of installation is Composer: composer require --dev "michaelmoussa/doctrine-qbmocker"

Dependencies

PHPUnit support

Contributing

I am no longer actively maintaining this project, but I do review and merge Pull Requests, so contributions are welcome. There are several unsupported methods still that would be non-trivial to implement. Please feel free to take care of those and send a PR.

All contributions must conform to PSR2 and include 100% test coverage.


All versions of doctrine-qbmocker with dependencies

PHP Build Version
Package Version
Requires php Version ^7.0.0
phpunit/phpunit Version ^6.0.0
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 michaelmoussa/doctrine-qbmocker contains the following files

Loading the files please wait ....