Skip to content

Commit

Permalink
Merge pull request #4 from doctrine/hotfix/cloneables-uniqueness-guar…
Browse files Browse the repository at this point in the history
…antee

Cloneables uniqueness guarantee
  • Loading branch information
deeky666 committed Aug 14, 2014
2 parents 7547e2c + c0302f3 commit e2b3294
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Doctrine/Instantiator/Instantiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function instantiate($className)

// not cloneable if it implements `__clone`, as we want to avoid calling it
if (! $reflection->hasMethod('__clone')) {
self::$cachedCloneables[$className] = $instance;
self::$cachedCloneables[$className] = clone $instance;
}

return $instance;
Expand Down
15 changes: 15 additions & 0 deletions tests/DoctrineTest/InstantiatorTest/InstantiatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ public function testInstantiationFromNonExistingClass($invalidClassName)
$this->instantiator->instantiate($invalidClassName);
}

public function testInstancesAreNotCloned()
{
$className = 'TemporaryClass' . uniqid();

eval('namespace ' . __NAMESPACE__ . '; class ' . $className . '{}');

$instance = $this->instantiator->instantiate(__NAMESPACE__ . '\\' . $className);

$instance->foo = 'bar';

$instance2 = $this->instantiator->instantiate(__NAMESPACE__ . '\\' . $className);

$this->assertObjectNotHasAttribute('foo', $instance2);
}

/**
* Provides a list of instantiable classes (existing)
*
Expand Down

0 comments on commit e2b3294

Please sign in to comment.