Skip to content

Commit

Permalink
Fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 6, 2011
1 parent ee07540 commit ee82245
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.markdown
Expand Up @@ -3,6 +3,11 @@ PHPUnit_MockObject 1.0

This is the list of changes for the PHPUnit_MockObject 1.0 release series.

PHPUnit_MockObject 1.0.8
------------------------

* The blacklist of uncloneable classes did not work for classes that extend an uncloneable class.

PHPUnit_MockObject 1.0.7
------------------------

Expand Down
43 changes: 28 additions & 15 deletions PHPUnit/Framework/MockObject/Invocation/Static.php
Expand Up @@ -71,16 +71,16 @@ class PHPUnit_Framework_MockObject_Invocation_Static implements PHPUnit_Framewor
* @var array
*/
protected static $uncloneableClasses = array(
'AppendIterator' => TRUE,
'CachingIterator' => TRUE,
'Closure' => TRUE,
'COMPersistHelper' => TRUE,
'IteratorIterator' => TRUE,
'LimitIterator' => TRUE,
'RecursiveCachingIterator' => TRUE,
'RecursiveRegexIterator' => TRUE,
'RegexIterator' => TRUE,
'ZipArchive' => TRUE
'AppendIterator',
'CachingIterator',
'Closure',
'COMPersistHelper',
'IteratorIterator',
'LimitIterator',
'RecursiveCachingIterator',
'RecursiveRegexIterator',
'RegexIterator',
'ZipArchive'
);

/**
Expand Down Expand Up @@ -142,24 +142,37 @@ public function toString()
*/
protected function cloneObject($original)
{
$cloneable = TRUE;
$cloneable = NULL;
$object = new ReflectionObject($original);

if (method_exists($object, 'isCloneable')) {
$cloneable = $object->isCloneable();
}

else if ($object->isInternal() &&
isset(self::$uncloneableExtensions[$object->getExtensionName()]) ||
isset(self::$uncloneableClasses[$object->getName()])) {
if ($cloneable === NULL &&
$object->isInternal() &&
isset(self::$uncloneableExtensions[$object->getExtensionName()])) {
$cloneable = FALSE;
}

else if ($object->hasMethod('__clone')) {
if ($cloneable === NULL && $object->hasMethod('__clone')) {
$method = $object->getMethod('__clone');
$cloneable = $method->isPublic();
}

if ($cloneable === NULL) {
foreach (self::$uncloneableClasses as $class) {
if ($original instanceof $class) {
$cloneable = FALSE;
break;
}
}
}

if ($cloneable === NULL) {
$cloneable = TRUE;
}

if ($cloneable) {
try {
return clone $original;
Expand Down

0 comments on commit ee82245

Please sign in to comment.