Bolt\EventListener\StorageEventListener::onUserEntityPreSave PHP Method

onUserEntityPreSave() public method

Pre-save storage event for user entities.
public onUserEntityPreSave ( Bolt\Events\StorageEvent $event )
$event Bolt\Events\StorageEvent
    public function onUserEntityPreSave(StorageEvent $event)
    {
        /** @var Entity\Users $entityRecord */
        $entityRecord = $event->getContent();
        if ($entityRecord instanceof Entity\Users) {
            $this->passwordHash($entityRecord);
        }
    }

Usage Example

Example #1
0
 /**
  * It should detect already hashed passwords.
  *
  * @dataProvider providePreSaveAlreadyHashed
  */
 public function testOnPreSavePasswordAlreadyHashed($hash)
 {
     $this->storageEvent->getContent()->willReturn($this->user->reveal());
     $this->user->getPassword()->willReturn($hash);
     $this->passwordFactory->createHash(Argument::cetera())->shouldNotBeCalled();
     $this->user->setPassword($hash)->shouldBeCalled();
     $this->listener->onUserEntityPreSave($this->storageEvent->reveal());
 }