예제 #1
0
 public function testAfterUpdateEvents()
 {
     $this->dispatcher->addListener(UserEvents::AFTER_UPDATE, function (UserEvent $event) {
         $event->getUser()->setCustomField('foo', 'bar');
     });
     $user = $this->userManager->createUser('*****@*****.**', 'password');
     $this->userManager->insert($user);
     // After update, the custom field set by the listener is available on the existing user instance.
     $this->assertFalse($user->hasCustomField('foo'));
     $this->userManager->update($user);
     $this->assertEquals('bar', $user->getCustomField('foo'));
     // The user was NOT stored with the custom field (because we set it AFTER update).
     // We'd have to save it again from within the after listener for it to be stored.
     $this->userManager->clearIdentityMap();
     // Clear the cache to force a fresh lookup from the database.
     $storedUser = $this->userManager->getUser($user->getId());
     $this->assertFalse($storedUser->hasCustomField('foo'));
 }