1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
|
UOPZ
====
*User Operations for Zend*
[](https://github.com/krakjoe/uopz/actions/workflows/ci.yml)
[](https://coveralls.io/github/krakjoe/uopz?branch=master)
The ```uopz``` extension is focused on providing utilities to aid with unit testing PHP code.
It supports the following activities:
- Intercepting function execution
- Intercepting object creation
- Hooking into function execution
- Manipulation of function statics
- Manipulation of function flags
- Redefinition of constants
- Deletion of constants
- Runtime creation of functions and methods
*Note: All of the above activities are compatible with opcache*
Requirements and Installation
=============================
If you use XDebug you need to use version 2.9.4 or higher.
See [INSTALL.md](INSTALL.md)
API
===
*The PHP API for ```uopz```*
```php
/**
* Provide a return value for an existing function
* @param string class
* @param string function
* @param mixed value
* @param bool execute
* If value is a Closure and execute flag is set, the Closure will
* be executed in place of the existing function
**/
function uopz_set_return(string class, string function, mixed value [, bool execute = 0]) : bool;
/**
* Provide a return value for an existing function
* @param string function
* @param mixed value
* @param bool execute
* If value is a Closure and execute flag is set, the Closure will
* be executed in place of the existing function
**/
function uopz_set_return(string function, mixed value [, bool execute = 0]) : bool;
/**
* Get a previously set return value
* @param string class
* @param string function
**/
function uopz_get_return(string class, string function) : mixed;
/**
* Get a previously set return value
* @param string function
**/
function uopz_get_return(string function) : mixed;
/**
* Unset a previously set return value
* @param string class
* @param string function
**/
function uopz_unset_return(string class, string function) : bool;
/**
* Unset a previously set return value
* @param string function
**/
function uopz_unset_return(string function) : bool;
/**
* Use mock in place of class
* @param string class
* @param mixed mock
* Mock can be an object, or the name of a class
**/
function uopz_set_mock(string class, mixed mock);
/**
* Get previously set mock for class
* @param string class
**/
function uopz_get_mock(string class);
/**
* Unset previously set mock
* @param string class
**/
function uopz_unset_mock(string class);
/**
* Get static variables from method scope
* @param string class
* @param string function
**/
function uopz_get_static(string class, string function) : array;
/**
* Get static variables from function scope
* @param string function
**/
function uopz_get_static(string function) : array;
/**
* Set static variables in method scope
* @param string class
* @param string function
* @param array static
**/
function uopz_set_static(string class, string function, array static);
/**
* Set static variables in function scope
* @param string function
* @param array static
**/
function uopz_set_static(string function, array static);
/**
* Execute hook when entering class::function
* @param string class
* @param string function
**/
function uopz_set_hook(string class, string function, Closure hook) : bool;
/**
* Execute hook when entering function
* @param string function
**/
function uopz_set_hook(string function, Closure hook) : bool;
/**
* Get previously set hook on class::function
* @param string class
* @param string function
**/
function uopz_get_hook(string class, string function) : Closure;
/**
* Get previously set hook on function
* @param string function
**/
function uopz_get_hook(string function) : Closure;
/**
* Remove previously set hook on class::function
* @param string class
* @param string function
**/
function uopz_unset_hook(string class, string function) : bool;
/**
* Remove previously set hook on function
* @param string function
**/
function uopz_unset_hook(string function) : bool;
/**
* Add a non-existent method
* @param string class
* @param string function
* @param Closure handler
* @param int flags
* @param bool all
* If all is true, all classes that descend from class will also be affected
**/
function uopz_add_function(string class, string function, Closure handler [, int flags = ZEND_ACC_PUBLIC [, bool all = true]]) : bool;
/**
* Add a non-existent function
* @param string function
* @param Closure handler
* @param int flags
* @param bool all
* If all is true, all classes that descend from class will also be affected
**/
function uopz_add_function(string function, Closure handler [, int flags = ZEND_ACC_PUBLIC [, bool all = true]]) : bool;
/**
* Delete a previously added method
* @param string class
* @param string function
* @param bool all
* If all is true, all classes that descend from class will also be affected
**/
function uopz_del_function(string class, string function, [, bool all = true]);
/**
* Delete a previously added function
* @param string function
**/
function uopz_del_function(string function);
/**
* Redefine $class::$constant to $value
* @param string class
* @param string constant
* @param mixed value
* Note: only user constants should be redefined
* Note: if the constant does not exist it will be created
**/
function uopz_redefine(string class, string constant, mixed value);
/**
* Redefine $constant to $value
* @param string constant
* @param mixed value
* Note: only user constants should be redefined
* Note: if the constant does not exist it will be created
**/
function uopz_redefine(string constant, mixed value);
/**
* Delete $class::$constant
* @param string class
* @param string constant
* Note: only user constants should be undefined
**/
function uopz_undefine(string class, string constant);
/**
* Delete $constant
* @param string constant
* Note: only user constants should be undefined
**/
function uopz_undefine(string constant);
/**
* Get or set flags on $class::$method()
* @param string class
* @param string method
* @param int flags
*/
function uopz_flags(string class, string method [, int flags]) : int;
/**
* Get or set flags on $method()
* @param string method
* @param int flags
*/
function uopz_flags(string function, [, int flags]) : int;
/**
* Set instance property
* @param object instance
* @param string property
* @param mixed value
*/
function uopz_set_property(object instance, string property, mixed value);
/**
* Set static class property
* @param string class
* @param string property
* @param mixed value
*/
function uopz_set_property(string class, string property, mixed value);
/**
* Get instance property
* @param object instance
* @param string property
*/
function uopz_get_property(object instance, string property) : mixed;
/**
* Get static class property
* @param string class
* @param string property
*/
function uopz_get_property(string class, string property) : mixed;
/**
* Retrieve the last set exit() status
* Note: opcache optimizes away dead code after unconditional exit
* Note: exit() breaks xdebug hooks
*/
function uopz_get_exit_status() : mixed;
/**
* Allows control over disabled exit opcode
* @param bool allow
* Note: by default exit will be ignored
*/
function uopz_allow_exit(bool allow) : void;
```
Supported Versions
==================
The currently supported version of uopz is 7 which requires PHP8.0+
Testing
=======
*Running the test suite*
After ``make`` has executed, run:
make test
You are done reading
====================
That is all !!!
|