3 * This file is part of the PHPUnit_MockObject package.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
12 * Implementation of the Builder pattern for Mock objects.
14 * @since File available since Release 1.0.0
16 class PHPUnit_Framework_MockObject_MockBuilder
19 * @var PHPUnit_Framework_TestCase
31 private $methods = array();
36 private $mockClassName = '';
41 private $constructorArgs = array();
46 private $originalConstructor = true;
51 private $originalClone = true;
56 private $autoload = true;
61 private $cloneArguments = false;
66 private $callOriginalMethods = false;
71 private $proxyTarget = null;
74 * @param PHPUnit_Framework_TestCase $testCase
75 * @param array|string $type
77 public function __construct(PHPUnit_Framework_TestCase $testCase, $type)
79 $this->testCase = $testCase;
84 * Creates a mock object using a fluent interface.
86 * @return PHPUnit_Framework_MockObject_MockObject
88 public function getMock()
90 return $this->testCase->getMock(
93 $this->constructorArgs,
95 $this->originalConstructor,
98 $this->cloneArguments,
99 $this->callOriginalMethods,
105 * Creates a mock object for an abstract class using a fluent interface.
107 * @return PHPUnit_Framework_MockObject_MockObject
109 public function getMockForAbstractClass()
111 return $this->testCase->getMockForAbstractClass(
113 $this->constructorArgs,
114 $this->mockClassName,
115 $this->originalConstructor,
116 $this->originalClone,
119 $this->cloneArguments
124 * Creates a mock object for a trait using a fluent interface.
126 * @return PHPUnit_Framework_MockObject_MockObject
128 public function getMockForTrait()
130 return $this->testCase->getMockForTrait(
132 $this->constructorArgs,
133 $this->mockClassName,
134 $this->originalConstructor,
135 $this->originalClone,
138 $this->cloneArguments
143 * Specifies the subset of methods to mock. Default is to mock all of them.
145 * @param array|null $methods
146 * @return PHPUnit_Framework_MockObject_MockBuilder
148 public function setMethods($methods)
150 $this->methods = $methods;
156 * Specifies the arguments for the constructor.
159 * @return PHPUnit_Framework_MockObject_MockBuilder
161 public function setConstructorArgs(array $args)
163 $this->constructorArgs = $args;
169 * Specifies the name for the mock class.
171 * @param string $name
172 * @return PHPUnit_Framework_MockObject_MockBuilder
174 public function setMockClassName($name)
176 $this->mockClassName = $name;
182 * Disables the invocation of the original constructor.
184 * @return PHPUnit_Framework_MockObject_MockBuilder
186 public function disableOriginalConstructor()
188 $this->originalConstructor = false;
194 * Enables the invocation of the original constructor.
196 * @return PHPUnit_Framework_MockObject_MockBuilder
197 * @since Method available since Release 1.2.0
199 public function enableOriginalConstructor()
201 $this->originalConstructor = true;
207 * Disables the invocation of the original clone constructor.
209 * @return PHPUnit_Framework_MockObject_MockBuilder
211 public function disableOriginalClone()
213 $this->originalClone = false;
219 * Enables the invocation of the original clone constructor.
221 * @return PHPUnit_Framework_MockObject_MockBuilder
222 * @since Method available since Release 1.2.0
224 public function enableOriginalClone()
226 $this->originalClone = true;
232 * Disables the use of class autoloading while creating the mock object.
234 * @return PHPUnit_Framework_MockObject_MockBuilder
236 public function disableAutoload()
238 $this->autoload = false;
244 * Enables the use of class autoloading while creating the mock object.
246 * @return PHPUnit_Framework_MockObject_MockBuilder
247 * @since Method available since Release 1.2.0
249 public function enableAutoload()
251 $this->autoload = true;
257 * Disables the cloning of arguments passed to mocked methods.
259 * @return PHPUnit_Framework_MockObject_MockBuilder
260 * @since Method available since Release 1.2.0
262 public function disableArgumentCloning()
264 $this->cloneArguments = false;
270 * Enables the cloning of arguments passed to mocked methods.
272 * @return PHPUnit_Framework_MockObject_MockBuilder
273 * @since Method available since Release 1.2.0
275 public function enableArgumentCloning()
277 $this->cloneArguments = true;
283 * Enables the invocation of the original methods.
285 * @return PHPUnit_Framework_MockObject_MockBuilder
286 * @since Method available since Release 2.0.0
288 public function enableProxyingToOriginalMethods()
290 $this->callOriginalMethods = true;
296 * Disables the invocation of the original methods.
298 * @return PHPUnit_Framework_MockObject_MockBuilder
299 * @since Method available since Release 2.0.0
301 public function disableProxyingToOriginalMethods()
303 $this->callOriginalMethods = false;
304 $this->proxyTarget = null;
310 * Sets the proxy target.
312 * @param object $object
313 * @return PHPUnit_Framework_MockObject_MockBuilder
314 * @since Method available since Release 2.0.0
316 public function setProxyTarget($object)
318 $this->proxyTarget = $object;