Skip to content

Commit 2b80b50

Browse files
committed
merged with master
1 parent b9979b0 commit 2b80b50

File tree

7 files changed

+45
-57
lines changed

7 files changed

+45
-57
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.2
1+
0.5.3

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
},
1515
"require": {
1616
"php": ">=5.4.0",
17-
"goaop/framework": "0.6.*"
17+
"goaop/framework": "0.6.*",
18+
"symfony/finder": "~2.4"
1819
},
1920
"require-dev": {
2021
"codeception/base": "~2.1",

docs/ClassProxy.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ $user->getCallsForMethod('someMethod') // [ ['arg1', 'arg2'] ]
4040
?>
4141
```
4242

43-
44-
45-
46-
47-
4843
#### *public* getCallsForMethod($method)
4944
#### *public* isDefined()
5045
Returns true if class exists.
@@ -75,7 +70,6 @@ Returns array of all trait names of a class.
7570

7671
* return array
7772

78-
7973
#### *public* construct()
8074
Creates an instance of a class via constructor.
8175

@@ -101,9 +95,6 @@ $user = test::double('User')->make();
10195
```
10296
* return object
10397

104-
105-
106-
10798
#### *public* verifyInvoked($name, $params = null)
10899
Verifies a method was invoked at least once.
109100
In second argument you can specify with which params method expected to be invoked;
@@ -162,3 +153,4 @@ $user->verifyNeverInvoked('setName',[]); // success
162153
* `param null` $params
163154
* throws \PHPUnit_Framework_ExpectationFailedException
164155

156+

docs/FuncProxy.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ $func->verifyNeverInvoked(['bye']);
2222
```
2323

2424

25-
26-
27-
2825
#### *public* verifyInvoked($params = null)
2926
* `param null` $params
3027

@@ -38,5 +35,5 @@ $func->verifyNeverInvoked(['bye']);
3835
* `param` $times
3936
* `param null` $params
4037

41-
4238
#### *public* getCallsForMethod($func)
39+

docs/InstanceProxy.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,12 @@ $user->getCallsForMethod('someMethod') // [ ['arg1', 'arg2'] ]
5353
```
5454

5555

56-
57-
58-
59-
60-
61-
6256
#### *public* getObject()
6357
Returns a real object that is proxified.
6458

6559
* return mixed
6660

6761
#### *public* getCallsForMethod($method)
68-
69-
70-
71-
7262
#### *public* verifyInvoked($name, $params = null)
7363
Verifies a method was invoked at least once.
7464
In second argument you can specify with which params method expected to be invoked;
@@ -127,3 +117,4 @@ $user->verifyNeverInvoked('setName',[]); // success
127117
* `param null` $params
128118
* throws \PHPUnit_Framework_ExpectationFailedException
129119

120+

docs/Test.md

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
`AspectMock\Test` class is a builder of test doubles.
77
Any 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.
89
This 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
1415
use 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.
1921
In 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
6668
test::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-
7273
test::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 ( ) )
8687
If you follow TDD/BDD practices a test should be written before the class is defined.
8788
If you would call undefined class in a test, a fatal error will be triggered.
8889
Instead 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.
126126
Thus, you can write a valid test before the class is declared.
127127

128128
If 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.
165164
Function 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+

src/AspectMock/Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ public static function double($classOrObject, array $params = array())
9797
if (!class_exists($classOrObject)) {
9898
throw new \Exception("Class $classOrObject not loaded.\nIf you want to test undefined class use 'test::spec' method");
9999
}
100-
if (!\class_exists($classOrObject)) $classOrObject = Registry::getNamespace().'\\'.$classOrObject;
101100

102101
Core\Registry::registerClass($classOrObject, $params);
103102
return new Proxy\ClassProxy($classOrObject);
@@ -106,6 +105,7 @@ public static function double($classOrObject, array $params = array())
106105
Core\Registry::registerObject($classOrObject, $params);
107106
return new Proxy\InstanceProxy($classOrObject);
108107
}
108+
return null;
109109
}
110110

111111
/**

0 commit comments

Comments
 (0)