Download the PHP package qratorlabs/smocky without Composer
On this page you can find all versions of the php package qratorlabs/smocky. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download qratorlabs/smocky
More information about qratorlabs/smocky
Files in qratorlabs/smocky
Package smocky
Short Description Mocking library based on runkit
License MIT
Homepage https://github.com/QratorLabs/Smocky
Informations about the package smocky
Mock static methods
...and a bit more ;)
Goals
- easy mocking
- make any changes revertible
- revert changes automatically
Targets
There are several classes that will do the work:
- To use with PHPUnit:
MockedMethod
to mock method "globally" and use PHPUnit's*Mockers
-expects/willReturn/willReturnCallback/...
MockedFunction
- For class methods:
MockedClassMethod
to mock any class with closureUndefinedClassMethod
to make method disappear
- For class constants:
MockedClassConstant
UndefinedClassConstant
- For global constants:
MockedGlobalConstant
UndefinedGlobalConstant
- For functions (global or Namespaced):
MockedFunction
UndefinedFunction
Install
MockedMethod
The main target is to make mocking static methods easy and feels-n-looks like using PHPUnit.
Note
There is a workaround that ensures that any (defined) children of class, which method is mocking, have its own method, defined by user or mocked (by Smocky - closure that calls parent).
Example for code that will fail without this workaround following code will end up with Segmentation fault: 11
Trivia
Revertible changes
All changes are made revertible by using internal storage and __destruct
methods.
Drawbacks
Thing to keep in mind before using:
- Mocking anything will hit memory consumption (ex. to preserve changes)
- Mocking methods will hit performance (a bit)
- To mock static class we must check (and mock) children of mocking class