57 $originalClassName, array $methods = array(), array $arguments = array(), $mockClassName =
'',
58 $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE
60 if ($originalClassName ===
'') {
61 throw new \InvalidArgumentException(
'$originalClassName must not be empty.', 1334701880);
64 return $this->getMock(
69 $callOriginalConstructor,
92 $originalClassName, array $arguments = array(), $mockClassName =
'',
93 $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE
95 if ($originalClassName ===
'') {
96 throw new \InvalidArgumentException(
'$originalClassName must not be empty.', 1384268260);
99 return $this->getMockForAbstractClass(
103 $callOriginalConstructor,
117 $accessibleClassName = str_replace(
'.',
'', $this->
getUniqueId(
'Tx_Phpunit_AccessibleProxy'));
118 $class = new \ReflectionClass($className);
119 $abstractModifier = $class->isAbstract() ?
'abstract ' :
'';
122 $abstractModifier .
'class ' . $accessibleClassName .
123 ' extends ' . $className .
' implements \TYPO3\CMS\Core\Tests\AccessibleObjectInterface {' .
124 'public function _call($methodName) {' .
125 'if ($methodName === \'\') {' .
126 'throw new \InvalidArgumentException(\'$methodName must not be empty.\', 1334663993);' .
128 '$args = func_get_args();' .
129 'return call_user_func_array(array($this, $methodName), array_slice($args, 1));' .
131 'public function _callRef(' .
132 '$methodName, &$arg1 = NULL, &$arg2 = NULL, &$arg3 = NULL, &$arg4 = NULL, &$arg5= NULL, &$arg6 = NULL, ' .
133 '&$arg7 = NULL, &$arg8 = NULL, &$arg9 = NULL' .
135 'if ($methodName === \'\') {' .
136 'throw new \InvalidArgumentException(\'$methodName must not be empty.\', 1334664210);' .
138 'switch (func_num_args()) {' .
140 'throw new RuntimeException(\'The case of 0 arguments is not supposed to happen.\', 1334703124);' .
143 '$returnValue = $this->$methodName();' .
146 '$returnValue = $this->$methodName($arg1);' .
149 '$returnValue = $this->$methodName($arg1, $arg2);' .
152 '$returnValue = $this->$methodName($arg1, $arg2, $arg3);' .
155 '$returnValue = $this->$methodName($arg1, $arg2, $arg3, $arg4);' .
158 '$returnValue = $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5);' .
161 '$returnValue = $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);' .
164 '$returnValue = $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7);' .
167 '$returnValue = $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8);' .
170 '$returnValue = $this->$methodName(' .
171 '$arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8, $arg9' .
175 'throw new \InvalidArgumentException(' .
176 '\'_callRef currently only allows calls to methods with no more than 9 parameters.\
'' .
179 'return $returnValue;' .
181 'public function _set($propertyName, $value) {' .
182 'if ($propertyName === \'\') {' .
183 'throw new \InvalidArgumentException(\'$propertyName must not be empty.\', 1334664355);' .
185 '$this->$propertyName = $value;' .
187 'public function _setRef($propertyName, &$value) {' .
188 'if ($propertyName === \'\') {' .
189 'throw new \InvalidArgumentException(\'$propertyName must not be empty.\', 1334664545);' .
191 '$this->$propertyName = $value;' .
193 'public function _setStatic($propertyName, $value) {' .
194 'if ($propertyName === \'\') {' .
195 'throw new \InvalidArgumentException(\'$propertyName must not be empty.\', 1344242602);' .
197 'self::$$propertyName = $value;' .
199 'public function _get($propertyName) {' .
200 'if ($propertyName === \'\') {' .
201 'throw new \InvalidArgumentException(\'$propertyName must not be empty.\', 1334664967);' .
203 'return $this->$propertyName;' .
205 'public function _getStatic($propertyName) {' .
206 'if ($propertyName === \'\') {' .
207 'throw new \InvalidArgumentException(\'$propertyName must not be empty.\', 1344242603);' .
209 'return self::$$propertyName;' .
214 return $accessibleClassName;
226 $arguments = func_get_args();
227 array_splice($arguments, 0, 2);
229 $reflectionObject = new \ReflectionObject($object);
230 $reflectionMethod = $reflectionObject->getMethod($name);
231 $reflectionMethod->setAccessible(TRUE);
232 return $reflectionMethod->invokeArgs($object, $arguments);
248 protected function inject($target, $name, $dependency) {
249 if (!is_object($target)) {
250 throw new \InvalidArgumentException(
'Wrong type for argument $target, must be object.');
253 $objectReflection = new \ReflectionObject($target);
254 $methodNamePart = strtoupper($name[0]) . substr($name, 1);
255 if ($objectReflection->hasMethod(
'set' . $methodNamePart)) {
256 $methodName =
'set' . $methodNamePart;
257 $target->$methodName($dependency);
258 } elseif ($objectReflection->hasMethod(
'inject' . $methodNamePart)) {
259 $methodName =
'inject' . $methodNamePart;
260 $target->$methodName($dependency);
261 } elseif ($objectReflection->hasProperty($name)) {
262 $property = $objectReflection->getProperty($name);
263 $property->setAccessible(TRUE);
264 $property->setValue($target, $dependency);
266 throw new \RuntimeException(
'Could not inject ' . $name .
' into object of type ' . get_class($target));
280 return $prefix . str_replace(
'.',
'', uniqid(mt_rand(), TRUE));
inject($target, $name, $dependency)
callInaccessibleMethod($object, $name)
getAccessibleMockForAbstractClass( $originalClassName, array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
buildAccessibleProxy($className)