Skip to content

Commit 1a7a185

Browse files
committed
updated docs and version
1 parent 9cd11cd commit 1a7a185

File tree

2 files changed

+1
-46
lines changed

2 files changed

+1
-46
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.0
1+
2.0.1

docs/Test.md

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -74,54 +74,9 @@ test::double('ActiveRecord', ['save' => false]);
7474
$user = new User(['name' => 'davert']);
7575
$user->save(); // false
7676

77-
# on conflicted stubs
78-
test::double('User', ['getGroup' => function () { return $this->group; }]);
79-
$user = new User;
80-
$user->group = 'guest';
81-
$user->getGroup(); // => guest
82-
test::double('User', ['getGroup' => function ($supersede = false) { return $supersede ? 'root' : __AM_CONTINUE__; }]);
83-
$user->group = 'user';
84-
$user->getGroup(true); // => root
85-
$user->getGroup(); // => user
86-
8777
?>
8878
```
8979

90-
#### Stacked Calls Support
91-
92-
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__.
124-
12580
* api
12681
* `param string|object` $classOrObject
12782
* `param array` $params [ 'methodName' => 'returnValue' ]

0 commit comments

Comments
 (0)