Download the PHP package davesweb/mockery-helper without Composer
On this page you can find all versions of the php package davesweb/mockery-helper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download davesweb/mockery-helper
More information about davesweb/mockery-helper
Files in davesweb/mockery-helper
Package mockery-helper
Short Description A set of helpers to create useful unit tests that use the Mockery library
License MIT
Informations about the package mockery-helper
Mockery Helper
A library to help you use Mockery in the best way possible.
Current stable version: 1.1.0
Installation
Via composer:
Use the --dev option if you only require your test dependencies in developer mode.
Via composer.json file:
You can also add this package directly to your composer.json file. Add the following line
to your require block, or require-dev block:
Then run:
Usage
Once you installed the package, you can use the provided trait in your tests:
This traits ensures that your Mockery expectations are enforced, because it expands on the
Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration trait. So if you use this trait, calling
\Mockery::close() is no longer needed.
Methods
This trait provides the following methods.
method
Signature:
If you need to pass a method name to a Mockery expectation, use this method to do so. This method accepts a callable as its argument, assuring that the method name you want to pass is recognised as such by an IDE. That way, when you refactor your code, the method name is also refactored in your Unit tests.
This method also checks to see if the method actually exists, so you don't make any typos in your method name.
The callable can be passed in the form of 'ClassName::method', [ClassName::class, 'method'] or
[$object, 'method'].
The method method returns the name of the method.
Example usage:
mock
Signature:
This is an alias for the Mockery::mock(...$args): MockerInterface call. Check the Mockery documentation
on how to use this method.
spy
Signature:
This is an alias for the Mockery::spy(...$args): MockerInterface call. Check the Mockery documentation
on how to use this method.
namedMock
Signature:
This is an alias for the Mockery::namedMock(...$args): MockerInterface call. Check the Mockery documentation
on how to use this method.
Skipping the check if a method exists.
Sometimes you want to be able to skip the check if a method is actually defined on a class, while
still keeping the refactor options. This can happen for instance if you use the magic __call() method
to handle some method calls.
In that case you can disable the check by overriding the allowNonExistingMethods property, or setting
it in your test:
You can also set the check per method call by adding a second parameter to the method call. Set it to true to
enforce the check, even if the global setting is to skip to check. Or set it to false to skip the check just for that
method call.
Contributing
Thank you for taking the time to improve this package! If you want to contribute to this package, please read to following file first: Contributing.