Pull merge.
[yaffs-website] / vendor / phpunit / phpunit-mock-objects / src / Framework / MockObject / MockBuilder.php
1 <?php
2 /*
3  * This file is part of the PHPUnit_MockObject package.
4  *
5  * (c) Sebastian Bergmann <sebastian@phpunit.de>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * Implementation of the Builder pattern for Mock objects.
13  *
14  * @since      File available since Release 1.0.0
15  */
16 class PHPUnit_Framework_MockObject_MockBuilder
17 {
18     /**
19      * @var PHPUnit_Framework_TestCase
20      */
21     private $testCase;
22
23     /**
24      * @var string
25      */
26     private $type;
27
28     /**
29      * @var array
30      */
31     private $methods = array();
32
33     /**
34      * @var string
35      */
36     private $mockClassName = '';
37
38     /**
39      * @var array
40      */
41     private $constructorArgs = array();
42
43     /**
44      * @var bool
45      */
46     private $originalConstructor = true;
47
48     /**
49      * @var bool
50      */
51     private $originalClone = true;
52
53     /**
54      * @var bool
55      */
56     private $autoload = true;
57
58     /**
59      * @var bool
60      */
61     private $cloneArguments = false;
62
63     /**
64      * @var bool
65      */
66     private $callOriginalMethods = false;
67
68     /**
69      * @var object
70      */
71     private $proxyTarget = null;
72
73     /**
74      * @param PHPUnit_Framework_TestCase $testCase
75      * @param array|string               $type
76      */
77     public function __construct(PHPUnit_Framework_TestCase $testCase, $type)
78     {
79         $this->testCase = $testCase;
80         $this->type     = $type;
81     }
82
83     /**
84      * Creates a mock object using a fluent interface.
85      *
86      * @return PHPUnit_Framework_MockObject_MockObject
87      */
88     public function getMock()
89     {
90         return $this->testCase->getMock(
91             $this->type,
92             $this->methods,
93             $this->constructorArgs,
94             $this->mockClassName,
95             $this->originalConstructor,
96             $this->originalClone,
97             $this->autoload,
98             $this->cloneArguments,
99             $this->callOriginalMethods,
100             $this->proxyTarget
101         );
102     }
103
104     /**
105      * Creates a mock object for an abstract class using a fluent interface.
106      *
107      * @return PHPUnit_Framework_MockObject_MockObject
108      */
109     public function getMockForAbstractClass()
110     {
111         return $this->testCase->getMockForAbstractClass(
112             $this->type,
113             $this->constructorArgs,
114             $this->mockClassName,
115             $this->originalConstructor,
116             $this->originalClone,
117             $this->autoload,
118             $this->methods,
119             $this->cloneArguments
120         );
121     }
122
123     /**
124      * Creates a mock object for a trait using a fluent interface.
125      *
126      * @return PHPUnit_Framework_MockObject_MockObject
127      */
128     public function getMockForTrait()
129     {
130         return $this->testCase->getMockForTrait(
131             $this->type,
132             $this->constructorArgs,
133             $this->mockClassName,
134             $this->originalConstructor,
135             $this->originalClone,
136             $this->autoload,
137             $this->methods,
138             $this->cloneArguments
139         );
140     }
141
142     /**
143      * Specifies the subset of methods to mock. Default is to mock all of them.
144      *
145      * @param  array|null                               $methods
146      * @return PHPUnit_Framework_MockObject_MockBuilder
147      */
148     public function setMethods($methods)
149     {
150         $this->methods = $methods;
151
152         return $this;
153     }
154
155     /**
156      * Specifies the arguments for the constructor.
157      *
158      * @param  array                                    $args
159      * @return PHPUnit_Framework_MockObject_MockBuilder
160      */
161     public function setConstructorArgs(array $args)
162     {
163         $this->constructorArgs = $args;
164
165         return $this;
166     }
167
168     /**
169      * Specifies the name for the mock class.
170      *
171      * @param  string                                   $name
172      * @return PHPUnit_Framework_MockObject_MockBuilder
173      */
174     public function setMockClassName($name)
175     {
176         $this->mockClassName = $name;
177
178         return $this;
179     }
180
181     /**
182      * Disables the invocation of the original constructor.
183      *
184      * @return PHPUnit_Framework_MockObject_MockBuilder
185      */
186     public function disableOriginalConstructor()
187     {
188         $this->originalConstructor = false;
189
190         return $this;
191     }
192
193     /**
194      * Enables the invocation of the original constructor.
195      *
196      * @return PHPUnit_Framework_MockObject_MockBuilder
197      * @since  Method available since Release 1.2.0
198      */
199     public function enableOriginalConstructor()
200     {
201         $this->originalConstructor = true;
202
203         return $this;
204     }
205
206     /**
207      * Disables the invocation of the original clone constructor.
208      *
209      * @return PHPUnit_Framework_MockObject_MockBuilder
210      */
211     public function disableOriginalClone()
212     {
213         $this->originalClone = false;
214
215         return $this;
216     }
217
218     /**
219      * Enables the invocation of the original clone constructor.
220      *
221      * @return PHPUnit_Framework_MockObject_MockBuilder
222      * @since  Method available since Release 1.2.0
223      */
224     public function enableOriginalClone()
225     {
226         $this->originalClone = true;
227
228         return $this;
229     }
230
231     /**
232      * Disables the use of class autoloading while creating the mock object.
233      *
234      * @return PHPUnit_Framework_MockObject_MockBuilder
235      */
236     public function disableAutoload()
237     {
238         $this->autoload = false;
239
240         return $this;
241     }
242
243     /**
244      * Enables the use of class autoloading while creating the mock object.
245      *
246      * @return PHPUnit_Framework_MockObject_MockBuilder
247      * @since  Method available since Release 1.2.0
248      */
249     public function enableAutoload()
250     {
251         $this->autoload = true;
252
253         return $this;
254     }
255
256     /**
257      * Disables the cloning of arguments passed to mocked methods.
258      *
259      * @return PHPUnit_Framework_MockObject_MockBuilder
260      * @since  Method available since Release 1.2.0
261      */
262     public function disableArgumentCloning()
263     {
264         $this->cloneArguments = false;
265
266         return $this;
267     }
268
269     /**
270      * Enables the cloning of arguments passed to mocked methods.
271      *
272      * @return PHPUnit_Framework_MockObject_MockBuilder
273      * @since  Method available since Release 1.2.0
274      */
275     public function enableArgumentCloning()
276     {
277         $this->cloneArguments = true;
278
279         return $this;
280     }
281
282     /**
283      * Enables the invocation of the original methods.
284      *
285      * @return PHPUnit_Framework_MockObject_MockBuilder
286      * @since  Method available since Release 2.0.0
287      */
288     public function enableProxyingToOriginalMethods()
289     {
290         $this->callOriginalMethods = true;
291
292         return $this;
293     }
294
295     /**
296      * Disables the invocation of the original methods.
297      *
298      * @return PHPUnit_Framework_MockObject_MockBuilder
299      * @since  Method available since Release 2.0.0
300      */
301     public function disableProxyingToOriginalMethods()
302     {
303         $this->callOriginalMethods = false;
304         $this->proxyTarget         = null;
305
306         return $this;
307     }
308
309     /**
310      * Sets the proxy target.
311      *
312      * @param  object                                   $object
313      * @return PHPUnit_Framework_MockObject_MockBuilder
314      * @since  Method available since Release 2.0.0
315      */
316     public function setProxyTarget($object)
317     {
318         $this->proxyTarget = $object;
319
320         return $this;
321     }
322 }