Recommend this page to a friend! |
![]() |
Info | Documentation | ![]() |
![]() |
![]() |
Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 54 | All time: 10,631 This week: 455![]() |
Version | License | PHP version | Categories | |||
doubles 1.0 | MIT/X Consortium ... | 5 | PHP 5, Language, Testing |
The "sitphp/doubles" library 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. This library can create doubles of any kind of class, interface or trait.
See full documentation : here
Add the line "sitphp/doubles": "2.2.*"
in the "require-dev"
section of your composer.json file :
{
"require-dev": {
"sitphp/doubles": "2.2.*"
}
}
And run the following command :
composer update
This will install the latest version of the "sitphp/doubles" library with the required PhpUnit package.
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 :
// Get a double instance of type "dummy" for class "MyClass"
$my_double = Double::dummy(MyClass::class)->getInstance();
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 :
// Get a double instance of type "mock" for class "MyClass"
$my_double = Double::mock(MyClass::class)->getInstance();
For more details : Read the doc on creating doubles
To test how many times a double method is called, use the count
method :
// Test that the method "myMethod" is called a least one time
$double::_method('myMethod')->count('>=1');
To test the values of the arguments passed to a double method, use the args
method :
// Test that the arguments passed to method "myMethod" are "value1" and "value2"
$double::_method('myMethod')->args(['value1', 'value2']);
To change the return value of a method, use the stub
method. :
// Make method "myMethod" return "hello"
$my_double::_method('myMethod')->return('hello');
For more details : Read the doc on testing doubles
You define the configuration for a specific double using the 2nd argument of the dummy
and mock
methods :</p>
// Get double instance with config
$my_double = Double::dummy(MyClass::class, [
'allow_final_doubles' => true,
'allow_non_existent_classes' => true
])->getInstance();
Here is a list of all available config parameters :
For more details : Read the doc on configuration
This library is licensed under the MIT license.
Alexandre Geiswiller - alexandre.geiswiller@gmail.com.
![]() |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() |
||||
![]() |
||||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Lic. | License text | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Doc. | Documentation |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
![]() |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.