Download the PHP package cyruscollier/phpspec-php-mock without Composer
On this page you can find all versions of the php package cyruscollier/phpspec-php-mock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cyruscollier/phpspec-php-mock
More information about cyruscollier/phpspec-php-mock
Files in cyruscollier/phpspec-php-mock
Package phpspec-php-mock
Short Description Adds the PHP Mock function mocking library as a phpspec Collaborator
License MIT
Homepage http://github.com/cyruscollier/phpspec-php-mock
Informations about the package phpspec-php-mock
PhpSpec - PHP-Mock Extension
Adds the PHP Mock function mocking library as a phpspec Collaborator
This phpspec extension allows you to mock non-deterministic PHP core functions (time()
, rand()
, etc.), or mock functions from other libraries or frameworks that have side effects from dependencies like a database, filesystem or HTTP request.
By using the specially named parameter $functions
in any example method, phpspec-php-mock will turn that parameter into a special FunctionCollaborator
that wraps the php-mock-prophecy library's PHPProphet
. This allows you to mock return values for any function as you normally would for an ObjectProphecy
.
Changelog
v2.1.2 - Fixed tests related to previous version, updated phpspec to 6.x
v2.1.1 - Interface return type fix
v2.1 - Added support for defining multiple namespaces for function prophecies
v2.0 - Updated for phpspec 4.x, added spec and doc for usage with Throw Matcher
v1.0 - Initial build for phpspec 2.x
Installation
Add this to your composer.json:
Then add this to your phpspec.yml:
Example
A PHP class that uses a non-deterministic function:
The spec for that class that mocks the time()
function:
Examples that test Exceptions require an extra line to reveal the function prophecy manually, since the Throw Matcher executes the Subject method differently than the other matchers :