diff --git a/Propel/User.php b/Propel/User.php index a620e785e2..9f0b61f398 100644 --- a/Propel/User.php +++ b/Propel/User.php @@ -48,6 +48,7 @@ public function serialize() $this->locked, $this->credentials_expired, $this->enabled, + $this->_new, ) ); } @@ -57,6 +58,12 @@ public function serialize() */ public function unserialize($serialized) { + $data = unserialize($serialized); + + // add a few extra elements in the array to ensure that we have enough keys when unserializing + // older data which does not include all properties. + $data = array_merge($data, array_fill(0, 1, null)); + list( $this->id, $this->username, @@ -65,8 +72,9 @@ public function unserialize($serialized) $this->expired, $this->locked, $this->credentials_expired, - $this->enabled - ) = unserialize($serialized); + $this->enabled, + $this->_new + ) = $data; } /** diff --git a/Tests/Propel/UserTest.php b/Tests/Propel/UserTest.php new file mode 100644 index 0000000000..1a7b46f1a6 --- /dev/null +++ b/Tests/Propel/UserTest.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\UserBundle\Propel; + +class UserTest extends \PHPUnit_Framework_TestCase +{ + protected function setUp() + { + if (!class_exists('Propel')) { + $this->markTestSkipped('Propel not installed'); + } + } + + public function testSerialize() + { + $group = new Group(); + $group->setName('Developers'); + + $user = new User(); + $user->setEmail('foobar@example.com'); + $user->setPassword('123456'); + $user->addGroup($group); + $user->save(); + + $userId = $user->getId(); + $this->assertInternalType('int', $userId); + + $serialized = serialize($user); + UserPeer::clearInstancePool(); + $this->assertCount(0, UserPeer::$instances); + + $unserialized = unserialize($serialized); + $fetchedUser = UserQuery::create()->findOneById($userId); + + $this->assertInstanceOf('FOS\UserBundle\Propel\User', $unserialized); + $this->assertCount(1, UserPeer::$instances); + $this->assertTrue($fetchedUser->equals($unserialized)); + + $this->assertCount(1, $unserialized->getGroups()); + } +} diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index 9f7e2f92ad..665b4497b7 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -22,5 +22,6 @@ $builder = new \PropelQuickBuilder(); $builder->getConfig()->setBuildProperty('behavior.typehintable.class', $class->getFileName()); $builder->setSchema(file_get_contents(__DIR__.'/../Resources/config/propel/schema.xml')); - $builder->buildClasses(); + $builder->setClassTargets(array('tablemap', 'peer', 'object', 'query')); + $builder->build(); }