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: CHANGELOG.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@
5
5
***Updated to Go AOP Framework 2.0**
6
6
* PHP7 (with typehints) supported
7
7
* Minimal PHP version is PHP 5.6
8
-
* Stacked support for mocked methods. You can register a chain of methods as a stub, and to control their execution.
8
+
*[Stacked functions support](https://github.com/Codeception/AspectMock/blob/master/docs/Test.md#Stacked-Calls-Support) for mocked methods. You can register a chain of methods as a stub, and to control their execution. By @torreytsui See https://github.com/Codeception/AspectMock/pull/91
Since 2.0 you can register multiple functions inside stib which will be executed in chain.
93
+
You can pass control to next function in a stack by returning `__AM_CONTINUE__` constant:
94
+
95
+
```php
96
+
class User {
97
+
public function getGroup() { return 'guest'; }
98
+
}
99
+
$user = new User;
100
+
```
101
+
102
+
So, it is for conflicted stubs, when a test double (e.g., getGroup) has been redefined.
103
+
104
+
```php
105
+
$stub1 = function () {
106
+
return 'user';
107
+
};
108
+
$stub2 = function ($supersede = false) {
109
+
return $supersede ? 'root' : __AM_CONTINUE__;
110
+
};
111
+
test::double('User', ['getGroup' => $stub1]);
112
+
test::double('User', ['getGroup' => $stub2]);
113
+
114
+
```
115
+
116
+
The idea basically is to allow a chain of responsibility passing through every conflicted stubs until a result returns. Use stack structure so that the latest defined stub will gain highest priority.
117
+
So, the result will look like this:
118
+
119
+
```php
120
+
$user->getGroup(true) // => root (handled by $stub2)
121
+
$user->getGroup() // => user (handled by $stub2 and then $stub1)
122
+
```
123
+
The $user->getGroup() // => user first handled by $stub2 and it gives up control by returning __AM_CONTINUE__, $stub1 then take place and return "user". If $stub1 return __AM_CONTINUE__, it will return control to the real object, as every stub has returned __AM_CONTINUE__.
0 commit comments