UserTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. }