Download the PHP package webxid/phpunitsandbox without Composer
On this page you can find all versions of the php package webxid/phpunitsandbox. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webxid/phpunitsandbox
More information about webxid/phpunitsandbox
Files in webxid/phpunitsandbox
Package phpunitsandbox
Short Description This package helps to make a mockups for unit-testing
License Apache-2.0
Informations about the package phpunitsandbox
PHPUnit Sandbox
This package helps to make a mockups for unit-testing in PHP v5.4 - 8.x
Source https://github.com/webxid/PHPUnitSandbox
Install
PHPUnitSandbox does not require any special installation.
Requirements
- PHP v5.4 or later,
- PHPUnitSandbox has to be includes directly (no autoloaders supports, including Composer),
- PHP config has to support functions
exec()
andeval()
.
Installation steps
- Run
composer require webxid/phpunitsandbox
- Register additional autoloaders, if you have any one
!!! Important !!! to make sandbox works correctly, the all autoloaders have to be register via UnitSandbox
, otherwise you get failed. Also, please, check ./bootstrap.php
How To Use
This lib works as sandbox:
- First, you setup a mock up of a class and of the class methods.
- Then, you call
UnitSandbox::execute(function() {});
and pass mocked class using inside thefunction() {}
.
Example
Code examples
Mock up a static method and an object method
Mocked classes are working inside another classes too
Spy class
Spy class uses to mock up a part of a class.
-
We need a
TestClass
for example: - Let's rewrite private property of class TestClass;
\ Please, see all examples in ./tests/ExampleUnitTest.php
Issues
To see errors, occurred inside sandbox, needs to set up debug mode:
License
PHPUnitSandbox is licensed under the Apache v2.0.
Version log
v0.3
- Make composer lib
-
Minor fixes
v0.2
- Mocked class properties defining
- Pass parameters to mocked methods
- Spy class logic
-
Minor fixes
v0.1
- Methods mock up features