Download the PHP package pbweb/mimic without Composer
On this page you can find all versions of the php package pbweb/mimic. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package mimic
Mimic
This library can be used to create mimics of your classes, which can be used for (functional) testing.
A mimicked class is similar to mock objects with stub methods in phpunit, but on a functional level.
Installation
Install with composer
Install mimic using composer:
Example
Lets say you have a client class which talks to an external REST service. The interface might look like this:
Now, using a class which really connects to the REST server in a (functional) test is a bad idea, since that server may not be in the scope of your test and influence the results.
To create a mimic client you need to extend MimicActionHandler like this:
Now you can mimic the behaviour of the RestClient in your tests:
Argument Matchers
In case you want more control over the arguments that are expected for a call, you can use argument matchers.
The ArgumentMatchers class instantiates several matchers which can be passed to the expected argument list of enqueue.
Usage
Extending MimicActionHandler will allow your class to have the mimic enqueue system.
Every method you want to mimic should have this as the body:
See tests/Service/SampleMimic for an example.
enableQueue
enableQueue will enable the use of the queue.
disableQueue
disableQueue will stop the use of the queue.
isQueueEnabled
isQueueEnabled will return a boolean value with the state of the queue.
enqueue
enqueue will add a method call to the expected queue.
You can add as many method prediction as you like.
If the next call to the mimic is the expected call then the given response will be returned and it will be removed from the queue.
If the next call to the mimic is not the same as the expected call added to the queue then an exception will be thrown.
If you set throw to true then the response will be thrown instead of returned.
getQueueContent
getQueueContent will return all the remaining actions added to the queue as Action models.
See the Action class for more information about the model.
isFinished
isFinished will return true if there are no more action left in the queue. false otherwise.
clearQueue
clearQueue will remove all the remaining actions from the queue.
All versions of mimic with dependencies
ext-json Version *