Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Support func_get_args() in __construct() of mock objects.

- Closes #118.
  • Loading branch information...
commit 0d350983c15fe360b82329f459de0424b20d53a3 1 parent 62285d4
@sebastianbergmann authored
Showing with 22 additions and 27 deletions.
  1. +22 −27 PHPUnit/Framework/MockObject/Mock.php
View
49 PHPUnit/Framework/MockObject/Mock.php
@@ -341,13 +341,13 @@ protected function generateConstructorCodeWithParentCall(ReflectionClass $class)
if ($constructor) {
return sprintf(
" public function __construct(%s) {\n" .
+ " $args = func_get_args();\n" .
" \$this->invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;\n" .
- " parent::%s(%s);\n" .
+ " call_user_func_array(array($this, 'parent::%s'), $args);\n" .
" }\n\n",
$this->generateMethodParameters($constructor),
- $constructor->getName(),
- $this->generateMethodParameters($constructor, TRUE)
+ $constructor->getName()
);
} else {
return $this->generateConstructorCode();
@@ -369,43 +369,38 @@ protected function generateCloneCodeWithParentCall()
" }\n\n";
}
- protected function generateMethodParameters(ReflectionMethod $method, $asCall = FALSE)
+ protected function generateMethodParameters(ReflectionMethod $method)
{
$list = array();
foreach ($method->getParameters() as $parameter) {
- $name = '$' . $parameter->getName();
+ $name = '$' . $parameter->getName();
+ $typeHint = '';
- if ($asCall) {
- $list[] = $name;
+ if ($parameter->isArray()) {
+ $typeHint = 'array ';
} else {
- $typeHint = '';
+ $class = $parameter->getClass();
- if ($parameter->isArray()) {
- $typeHint = 'array ';
- } else {
- $class = $parameter->getClass();
-
- if ($class) {
- $typeHint = $class->getName() . ' ';
- }
+ if ($class) {
+ $typeHint = $class->getName() . ' ';
}
+ }
- $default = '';
-
- if ($parameter->isDefaultValueAvailable()) {
- $value = $parameter->getDefaultValue();
- $default = ' = ' . var_export($value, TRUE);
- }
+ $default = '';
- $ref = '';
+ if ($parameter->isDefaultValueAvailable()) {
+ $value = $parameter->getDefaultValue();
+ $default = ' = ' . var_export($value, TRUE);
+ }
- if ($parameter->isPassedByReference()) {
- $ref = '&';
- }
+ $ref = '';
- $list[] = $typeHint . $ref . $name . $default;
+ if ($parameter->isPassedByReference()) {
+ $ref = '&';
}
+
+ $list[] = $typeHint . $ref . $name . $default;
}
return join(', ', $list);
Please sign in to comment.
Something went wrong with that request. Please try again.