You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22-6Lines changed: 22 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,26 @@ This provides four monkey patchers.
9
9
-`MethodPatcher`: Patches Methods in User-defined Classes
10
10
-`ConstantPatcher`: Changes Constant Values
11
11
12
+
## Table of Contents
13
+
14
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
15
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
16
+
17
+
-[Requirements](#requirements)
18
+
-[Installation](#installation)
19
+
-[Usage](#usage)
20
+
-[Configure](#configure)
21
+
-[Convert `exit()` to Exception](#convert-exit-to-exception)
22
+
-[Patch Functions](#patch-functions)
23
+
-[Change Return Value](#change-return-value)
24
+
-[Patch Other Functions](#patch-other-functions)
25
+
-[Patch Methods in User-defined Classes](#patch-methods-in-user-defined-classes)
26
+
-[Patch Constants](#patch-constants)
27
+
-[Class Reference](#class-reference)
28
+
-[License](#license)
29
+
30
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
31
+
12
32
## Requirements
13
33
14
34
- PHP 7.3 or later
@@ -84,11 +104,9 @@ So by default we can replace only a dozen pre-defined functions in [FunctionPatc
84
104
85
105
[MonkeyPatch::patchFunction()]() replaces PHP native function `mt_rand()` in `Welcome::index` method, and it will return `100` in the test method.
86
106
87
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v3.0.0/application/tests/controllers/Patching_on_function_test.php).
88
-
89
107
**Note:** If you call `MonkeyPatch::patchFunction()` without 3rd argument, all the functions (located in `include_paths` and not in `exclude_paths`) called in the test method will be replaced. So, for example, a function in CodeIgniter code might be replaced and it results in unexpected outcome.
90
108
91
-
**Change Return Value**
109
+
#### Change Return Value
92
110
93
111
You could change return value of patched function using PHP closure:
94
112
@@ -117,9 +135,7 @@ You could change return value of patched function using PHP closure:
117
135
);
118
136
~~~
119
137
120
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v3.0.0/application/tests/controllers/Patching_on_function_test.php#L59-L80).
121
-
122
-
**Patch Other Functions**
138
+
#### Patch Other Functions
123
139
124
140
If you want to patch other functions, you can add them to [functions_to_patch](https://github.com/kenjis/ci-phpunit-test/blob/a4f8ceb4b96650529565be23a77f5dfcda8d4cce/application/tests/Bootstrap.php#L369-L371) in `MonkeyPatchManager::init()`.
0 commit comments