Download the PHP package gealex/doublit without Composer
On this page you can find all versions of the php package gealex/doublit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gealex/doublit
More information about gealex/doublit
Files in gealex/doublit
Package doublit
Short Description Doublit : A simple tool to test your class dependencies in PhpUnit
License MIT
Homepage https://github.com/gealex/doublit
Informations about the package doublit
Doublit - Double and test PHP classes easily in PhpUnit
Doublit can help you to test your PHP classes by generating doubles that look like the original classes but can be manipulated and tested (sort of a copy of a class). These doubles then can then be used instead of the original classes for your test. Doublit can create doubles of any kind of class, interface or trait.
See full documentation at https://getdoublit.com
Installation
Add the line "gealex/doublit": "~2.1.0"
in the "require-dev"
section of your composer.json file :
{
"require-dev": {
"gealex/doublit": "~2.1.0"
}
}
And run the following command :
$ composer update
This will install the latest version of Doublit with the required PhpUnit package.
Creating a double
A double is called a "dummy" when all the methods of the original class are overwritten to return null
. To get a "dummy" double instance, use the dummy
method :
A double is called a "mock" when all the methods of the original class are overwritten to behave the same as in the original class. To get a "mock" double instance, use the mock
method :
For more details : Read the doc on creating doubles
Testing a double
To test how many times a double method is called, use the count
method :
To test the values of the arguments passed to a double method, use the args
method :
To change the return value of a method, use the stub
method. :
For more details : Read the doc on testing doubles
Configuration
You define the configuration for a specific double using the 2nd argument of the dummy
and mock
methods :
Here is a list of all available config parameters :
allow_final_doubles
: Set this parameter tofalse
to stop Doublit from trying to make doubles of final classes/methods.allow_protected_methods
: Set this parameter tofalse
to disallow testing protected methods.allow_non_existent_classes
: Set this parameter tofalse
to disallow alias doubles of non existent classes.test_unexpected_methods
: Set this parameter totrue
to automatically receive an assertion error whenever an unexpected method is called.
For more details : Read the doc on configuration
About
License
Doublit is licensed under the MIT license.
Author
Alexandre Geiswiller - [email protected].
For more details : Read the doc on about