55
66` AspectMock\Test ` class is a builder of test doubles.
77Any object can be enhanced and turned to a test double with the call to ` double ` method.
8+ Mocking abstract classes and interfaces is not supported at this time.
89This allows to redefine any method of object with your own, and adds mock verification methods.
910
1011** Recommended Usage** :
@@ -14,15 +15,16 @@ This allows to redefine any method of object with your own, and adds mock verifi
1415use AspectMock\Test as test;
1516?>
1617```
17- #### * public static* double($classOrObject, $params = null)
18- test::double registers class or object to track its calls.
18+
19+ #### * public static* double($classOrObject, array $params = Array ( ) )
20+ ` test::double ` registers class or object to track its calls.
1921In second argument you may pass values that mocked mathods should return.
2022
21- Returns either of [ ** ClassProxy** ] ( https://github.com/Codeception/AspectMock/blob/master/docs/ClassProxy.md )
22- or [ ** InstanceProxy** ] ( https://github.com/Codeception/AspectMock/blob/master/docs/InstanceProxy.md ) .
23- Proxies are used to verify method invocations, and some other useful things.
23+ Returns either of [ ** ClassProxy** ] ( https://github.com/Codeception/AspectMock/blob/master/docs/ClassProxy.md ) (when a string was passed)
24+ or [ ** InstanceProxy** ] ( https://github.com/Codeception/AspectMock/blob/master/docs/InstanceProxy.md ) (when an object was passed) .
25+ Proxies are used to verify method invocations, and some other useful things (check out the links above for more) .
2426
25- Example :
27+ Examples :
2628
2729``` php
2830<?php
@@ -64,11 +66,10 @@ test::double('User')->make(); // without calling constructor
6466
6567# stub for magic method
6668test::double('User', ['findByUsernameAndPasswordAndEmail' => false]);
67- User::findByUsernameAndPasswordAndEmail; // null
69+ User::findByUsernameAndPasswordAndEmail() ; // null
6870
6971# stub for method of parent class
7072# if User extends ActiveRecord
71-
7273test::double('ActiveRecord', ['save' => false]);
7374$user = new User(['name' => 'davert']);
7475$user->save(); // false
@@ -77,12 +78,12 @@ $user->save(); // false
7778```
7879
7980 * api
80- * ` param ` $classOrObject
81- * ` param array ` $params
81+ * ` param string|object ` $classOrObject
82+ * ` param array ` $params [ 'methodName' => 'returnValue' ]
8283 * throws \Exception
83- * return Verifier
84+ * return Verifier Usually Proxy\ClassProxy|Proxy\InstanceProxy
8485
85- #### * public static* spec($classOrObject, $params = null )
86+ #### * public static* spec($classOrObject, array $params = Array ( ) )
8687If you follow TDD/BDD practices a test should be written before the class is defined.
8788If you would call undefined class in a test, a fatal error will be triggered.
8889Instead you can use ` test::spec ` method that will create a proxy for an undefined class.
@@ -94,22 +95,21 @@ $userClass->defined(); // false
9495?>
9596```
9697
97- You can create instances of undefined classes and play with them.
98+ You can create instances of undefined classes and play with them:
9899
99100``` php
100101<?php
101102$user = test::spec('User')->construct();
102103$user->setName('davert');
103104$user->setNumPosts(count($user->getPosts()));
104105$this->assertEquals('davert', $user->getName()); // fail
105-
106106?>
107107```
108108
109- The test will be executed normally and will fail on the first assertion.
109+ The test will be executed normally and will fail at the first assertion.
110110
111111` test::spec()->construct ` creates an instance of ` AspectMock\Proxy\Anything `
112- which tries to not cause errors whatever you try to do with it.
112+ which tries not to cause errors whatever you try to do with it.
113113
114114``` php
115115<?php
@@ -122,19 +122,18 @@ foreach ($user->names as $name) {
122122?>
123123```
124124
125- None of this calls will trigger error on your test.
125+ None of those calls will trigger an error in your test.
126126Thus, you can write a valid test before the class is declared.
127127
128128If class is already defined, ` test::spec ` will act as ` test::double ` .
129129
130130 * api
131- * ` param ` $classOrObject
131+ * ` param string|object ` $classOrObject
132132 * ` param array ` $params
133- * return Verifier
134-
133+ * return Verifier Usually Proxy\ClassProxy|Proxy\InstanceProxy
135134
136135#### * public static* methods($classOrObject, array $only = Array ( ) )
137- Replaces all methods in a class with a dummies, except specified.
136+ Replaces all methods in a class with dummies, except those specified in the ` $only ` param .
138137
139138``` php
140139<?php
@@ -145,7 +144,7 @@ $user->getName(); // jon
145144?>
146145```
147146
148- You can create a dummy without a constructor with all methods disabled
147+ You can create a dummy without a constructor with all methods disabled:
149148
150149``` php
151150<?php
@@ -155,13 +154,13 @@ test::methods($user, []);
155154```
156155
157156 * api
158- * ` param ` $classOrObject
159- * ` param array ` $only
160- * return Core \ClassProxy|Core \InstanceProxy
157+ * ` param string|object ` $classOrObject
158+ * ` param string[] ` $only
159+ * return Verifier Usually Proxy \ClassProxy|Proxy \InstanceProxy
161160 * throws \Exception
162161
163- #### * public static* func($namespace, $function , $body)
164- Replaces function in provided namespace with user-defined function or value that function returns;
162+ #### * public static* func($namespace, $functionName , $body)
163+ Replaces function in provided namespace with user-defined function or value that function returns.
165164Function is restored to original on cleanup.
166165
167166``` php
@@ -180,7 +179,7 @@ test::func('demo', 'date', function($format) {
180179
181180```
182181
183- Mocked functions can be verified for calls.
182+ Mocked functions can be verified for calls:
184183
185184``` php
186185<?php
@@ -191,9 +190,9 @@ $func->verifyInvoked();
191190$func->verifyInvokedOnce(['Y']);
192191```
193192
194- * ` param ` $namespace
195- * ` param ` $function
196- * ` param ` $body
193+ * ` param string ` $namespace
194+ * ` param string ` $functionName
195+ * ` param mixed ` $body whatever a function might return or Callable substitute
197196 * return Proxy\FuncProxy
198197
199198#### * public static* clean($classOrInstance = null)
@@ -216,5 +215,13 @@ test::clean($user);
216215```
217216
218217 * api
218+ * ` param string|object ` $classOrObject
219+ * return void
219220
220221#### * public static* cleanInvocations()
222+ Clears mock verifications but not stub definitions.
223+
224+ * api
225+ * return void
226+
227+
0 commit comments