Permalink
Browse files

- Fix #119.

  • Loading branch information...
1 parent ec6ddf0 commit c45883e305da65ad587698899ac373a55e5bb057 @sebastianbergmann committed Apr 26, 2007
Showing with 24 additions and 1 deletion.
  1. +24 −1 PHPUnit/Framework/MockObject/Invocation.php
@@ -87,7 +87,7 @@ public function __construct($object, $className, $methodName, $parameters)
foreach ($this->parameters as $key => $value) {
if (is_object($value)) {
- $this->parameters[$key] = clone $value;
+ $this->parameters[$key] = $this->cloneObject($value);
}
}
}
@@ -111,5 +111,28 @@ public function toString()
)
);
}
+
+ protected function cloneObject($original)
+ {
+ $object = new ReflectionObject($original);
+
+ if ($object->hasMethod('__clone')) {
+ $method = $object->getMethod('__clone');
+
+ if (!$method->isPublic()) {
+ return $original;
+ }
+
+ try {
+ return clone $original;
+ }
+
+ catch (Exception $e) {
+ return $original;
+ }
+ }
+
+ return clone $original;
+ }
}
?>

0 comments on commit c45883e

Please sign in to comment.