Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public function __construct(

public function registerPassword(FormEvent $event)
{
if (null === $event->getData() || '' === $event->getData()) {
return;
}

$this->assertNotMapped($event->getForm());

$this->passwords[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Form\Exception\InvalidConfigurationException;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\PasswordHasher\EventListener\PasswordHasherListener;
Expand Down Expand Up @@ -80,6 +81,36 @@ public function testPasswordHashSuccess()
$this->assertSame($user->getPassword(), $hashedPassword);
}

public function testPasswordHashSkippedWithEmptyPassword()
{
$oldHashedPassword = 'PreviousHashedPassword';

$user = new User();
$user->setPassword($oldHashedPassword);

$this->passwordHasher
->expects($this->never())
->method('hashPassword')
;

$this->assertEquals($user->getPassword(), $oldHashedPassword);

$form = $this->factory
->createBuilder(FormType::class, $user)
->add('plainPassword', PasswordType::class, [
'hash_property_path' => 'password',
'mapped' => false,
'required' => false,
])
->getForm()
;

$form->submit(['plainPassword' => '']);

$this->assertTrue($form->isValid());
$this->assertSame($user->getPassword(), $oldHashedPassword);
}

public function testPasswordHashSuccessWithEmptyData()
{
$user = new User();
Expand Down