UserTest.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. * This file is part of the FOSUserBundle package.
  4. *
  5. * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace FOS\UserBundle\Propel;
  11. class UserTest extends \PHPUnit_Framework_TestCase
  12. {
  13. protected function setUp()
  14. {
  15. if (!class_exists('Propel')) {
  16. $this->markTestSkipped('Propel not installed');
  17. }
  18. }
  19. public function testSerialize()
  20. {
  21. $group = new Group();
  22. $group->setName('Developers');
  23. $user = new User();
  24. $user->setEmail('foobar@example.com');
  25. $user->setPassword('123456');
  26. $user->addGroup($group);
  27. $user->save();
  28. $userId = $user->getId();
  29. $this->assertInternalType('int', $userId);
  30. $serialized = serialize($user);
  31. UserPeer::clearInstancePool();
  32. $this->assertCount(0, UserPeer::$instances);
  33. $unserialized = unserialize($serialized);
  34. $fetchedUser = UserQuery::create()->findOneById($userId);
  35. $this->assertInstanceOf('FOS\UserBundle\Propel\User', $unserialized);
  36. $this->assertCount(1, UserPeer::$instances);
  37. $this->assertTrue($fetchedUser->equals($unserialized));
  38. $this->assertCount(1, $unserialized->getGroups());
  39. }
  40. }