fix validation for create user command (#709)

This commit is contained in:
Kevin Papst
2019-04-17 00:20:38 +02:00
committed by GitHub
parent 3251b26d9e
commit 48f3ad842d
2 changed files with 15 additions and 3 deletions

View File

@@ -111,7 +111,7 @@ class CreateUserCommand extends Command
$pwd = $this->encoder->encodePassword($user, $user->getPlainPassword());
$user->setPassword($pwd);
$errors = $this->validator->validate($user, null, ['registration']);
$errors = $this->validator->validate($user, null, ['Registration']);
if ($errors->count() > 0) {
/** @var \Symfony\Component\Validator\ConstraintViolation $error */
foreach ($errors as $error) {

View File

@@ -72,8 +72,10 @@ class CreateUserCommandTest extends KernelTestCase
{
$commandTester = $this->createUser('xx', '', 'ROLE_USER', '');
$output = $commandTester->getDisplay();
$this->assertContains('[ERROR] email ()', $output);
$this->assertContains('Please enter an email', $output);
$this->assertContains('[ERROR] plainPassword ()', $output);
// TODO the test validator is misconfigured, doesn't find "short username" and "empty email"
$this->assertContains('Please enter a password', $output);
}
public function testUserAlreadyExisting()
@@ -82,6 +84,16 @@ class CreateUserCommandTest extends KernelTestCase
$commandTester = $this->createUser('MyTestUser', 'user@example.com', 'ROLE_USER', 'foobar');
$output = $commandTester->getDisplay();
$this->assertContains('[ERROR] Failed to create user: MyTestUser', $output);
$this->assertContains('[ERROR] username (mytestuser)', $output);
$this->assertContains('The username is already used', $output);
}
public function testUserEmail()
{
$commandTester = $this->createUser('MyTestUser', 'ROLE_USER', 'ROLE_USER', 'foobar');
$output = $commandTester->getDisplay();
$this->assertContains('[ERROR] email (ROLE_USER)', $output);
$this->assertContains('The email is not valid', $output);
}
}