From 48f3ad842da500a6c23a3b242619c275a0f0a540 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Wed, 17 Apr 2019 00:20:38 +0200 Subject: [PATCH] fix validation for create user command (#709) --- src/Command/CreateUserCommand.php | 2 +- tests/Command/CreateUserCommandTest.php | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Command/CreateUserCommand.php b/src/Command/CreateUserCommand.php index 8d0b4446..2a843111 100644 --- a/src/Command/CreateUserCommand.php +++ b/src/Command/CreateUserCommand.php @@ -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) { diff --git a/tests/Command/CreateUserCommandTest.php b/tests/Command/CreateUserCommandTest.php index 4a7c9f77..37157704 100644 --- a/tests/Command/CreateUserCommandTest.php +++ b/tests/Command/CreateUserCommandTest.php @@ -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); } }