Download the PHP package czukowski/phpunit-mock-dibi without Composer

On this page you can find all versions of the php package czukowski/phpunit-mock-dibi. 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 phpunit-mock-dibi

Dibi mocking helpers for PHPUnit

PHPUnit

A mock-object library for database queries testing, without having to initialize in-memory database from fixtures. Rather, every query executed by a tested code can be set to return a pre-defined result set, affected rows count or last insert ID. All with a familiar interface similar to PHPUnit Mock Objects.

This is an adapted version of czukowski/phpunit-mock-db package for uses of Dibi - smart database layer for PHP by David Grudl. Dibi is a database connection library that includes a powerful query builder and supports a variety of relational database systems.

Installation

Install using Composer:

Usage

Use Cz\PHPUnit\MockDibi\MockTrait trait in a test case class, this will enable methods for creating database mock instances. Just call createDatabaseMock method passing a Dibi\Connection instance that uses one of the mock drivers provided in this package, and a mock object will be added to it and registered to the test case class.

There is a handy factory class for mock Dibi drivers in Cz\PHPUnit\MockDibi\Drivers\DriversFactory so you don't have to create driver instances yourself (see its source code for methods available).

Example how to create mock Dibi Connection:

Examples how to set up expected queries and mock results:

Return a pre-defined result set on any database query:

Return a pre-defined result set on any database query and expect it to be executed exactly once:

Return a pre-defined result set on each specific database query, expecting each query to be executed exactly once:

Note: the order in which the query expectations are being set up doesn't have to be same as the order in which the queries will be executed.

Also note: the whitespaces will be ignored in query constraints, so they can be loaded from well-formatted files, which could be especially useful for long and complex queries.

Also note: different Dibi drivers may use different characters to quote identifiers, eg. backticks for MySQL or square brackets for MS SQL Server, etc. Query constraints will use Dibi Translator to transform queries so there's no need to take extra care to have identifiers quotes matching the currently used driver.

Expect mixed queries, some at specific invocations (note: SELECT query is set to return an empty result set):

Expect same query executed exactly three times and return different last insert IDs on each consecutive call:

Return affected rows count:

Match SQL query using PHPUnit constraint (note: whitespace will not be ignored when using default PHPUnit constraints):

Set up different outcomes on consecutive calls for INSERT queries using a consecutive calls stub builder:

Although not normally needed, it is possible to set up custom callbacks to handle database queries (callbacks don't have to return anything):

By default, mock object is set to throw an exception if an unknown (unmatched) query is executed, but this can be disabled:

License

This work is released under the MIT License. See LICENSE.md for details.


All versions of phpunit-mock-dibi with dependencies

PHP Build Version
Package Version
Requires czukowski/phpunit-mock-db Version ^7.0 || >= 8.2
czukowski/phpunit-sql Version ^7.0.2 || ^8.0 || ^9.0
dibi/dibi Version ~4.2.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 czukowski/phpunit-mock-dibi contains the following files

Loading the files please wait ....