Skip to content

Commit

Permalink
Fix unserialization behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
dzubchik committed Mar 9, 2017
1 parent f40205a commit 547e92b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Immutable.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ final public function __get($name)

return $this->_defaultValues[$name];
}

final public function __wakeup()
{
foreach ($this->_userDefinedProperties as $property => $defined) {
unset($this->{$property});
}
}
}
25 changes: 25 additions & 0 deletions test/SerializationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php


namespace ConvenientImmutability\Test;

use ConvenientImmutability\Test\Resources\Foo;

class SerializationTest extends \PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function it_should_be_same_after_serialization()
{
$foo = new Foo();
$foo->bar = 1;
$foo->baz = 2;

$serializedValue = serialize($foo);
$deSerializedValue = unserialize($serializedValue);

$this->assertSame($deSerializedValue->bar, $foo->bar);
$this->assertSame($deSerializedValue->baz, $foo->baz);
}
}

0 comments on commit 547e92b

Please sign in to comment.