public function testDelegatesImmutabilityToTheDecoratedObject()
{
// Case where the decorated object is mutable
$decoratedObject = new SimpleObject('dummy', $instance = new \stdClass());
$object = new CompleteObject($decoratedObject);
$instance->foo = 'bar';
$object->getInstance()->foz = 'baz';
$clone = clone $object;
$instance->fao = 'bor';
$clone->getInstance()->faz = 'boz';
$this->assertEquals(StdClassFactory::create(['foo' => 'bar', 'foz' => 'baz', 'fao' => 'bor', 'faz' => 'boz']), $object->getInstance());
$this->assertEquals($object->getInstance(), $clone->getInstance());
// Case where the decorated object is partially immutable: cloning does create a new instance
$decoratedObject = new ImmutableByCloneObject('dummy', $instance = new \stdClass());
$object = new CompleteObject($decoratedObject);
$instance->foo = 'bar';
$object->getInstance()->foz = 'baz';
$clone = clone $object;
$instance->fao = 'bor';
$clone->getInstance()->faz = 'boz';
$this->assertEquals(StdClassFactory::create(['foo' => 'bar', 'foz' => 'baz', 'fao' => 'bor']), $object->getInstance());
$this->assertEquals(StdClassFactory::create(['foo' => 'bar', 'foz' => 'baz', 'faz' => 'boz']), $clone->getInstance());
// Case where the decorated object is truly immutable
$decoratedObject = new ImmutableObject('dummy', $instance = new \stdClass());
$object = new CompleteObject($decoratedObject);
$instance->foo = 'bar';
$object->getInstance()->foz = 'baz';
$clone = clone $object;
$instance->fao = 'bor';
$clone->getInstance()->faz = 'boz';
$this->assertEquals(new \stdClass(), $object->getInstance());
$this->assertEquals(new \stdClass(), $clone->getInstance());
}