Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)

This commit is contained in:
Kevin Papst
2022-12-31 21:19:55 +01:00
committed by GitHub
parent 95e06746bd
commit 90a0fd8a22
2164 changed files with 83700 additions and 86426 deletions

View File

@@ -23,10 +23,7 @@ use Symfony\Component\Console\Tester\CommandTester;
*/
class CreateUserCommandTest extends KernelTestCase
{
/**
* @var Application
*/
private $application;
private Application $application;
protected function setUp(): void
{
@@ -40,16 +37,15 @@ class CreateUserCommandTest extends KernelTestCase
));
}
public function testCreateUserFailsForShortPassword()
public function testCreateUserFailsForShortPassword(): void
{
$commandTester = $this->createUser('MyTestUser', 'user@example.com', 'ROLE_USER', 'foobar');
$output = $commandTester->getDisplay();
$this->assertStringContainsString('[ERROR] plainPassword (foobar)', $output);
$this->assertStringContainsString('This value is too short. It should have 8 characters or more.', $output);
$this->assertStringContainsString('[ERROR] plainPassword: This value is too short.', $output);
}
public function testCreateUser()
public function testCreateUser(): void
{
$commandTester = $this->createUser('MyTestUser', 'user@example.com', 'ROLE_USER', 'foobar12');
@@ -59,12 +55,12 @@ class CreateUserCommandTest extends KernelTestCase
$container = self::$kernel->getContainer();
/** @var UserRepository $userRepository */
$userRepository = $container->get('doctrine')->getRepository(User::class);
$user = $userRepository->loadUserByUsername('MyTestUser');
$user = $userRepository->loadUserByIdentifier('MyTestUser');
self::assertInstanceOf(User::class, $user);
self::assertNotNull($user);
}
protected function createUser($username, $email, $role, $password)
protected function createUser($username, $email, $role, $password): CommandTester
{
$command = $this->application->find('kimai:user:create');
$commandTester = new CommandTester($command);
@@ -79,44 +75,38 @@ class CreateUserCommandTest extends KernelTestCase
return $commandTester;
}
public function testUserWithEmptyFieldsTriggersValidationProblem()
public function testUserWithEmptyFieldsTriggersValidationProblem(): void
{
$commandTester = $this->createUser('xx', '', 'ROLE_USER', '');
$output = $commandTester->getDisplay();
$this->assertStringContainsString('[ERROR] email ()', $output);
$this->assertStringContainsString('This value should not be blank', $output);
$this->assertStringContainsString('[ERROR] plainPassword ()', $output);
$this->assertStringContainsString('This value should not be blank', $output);
$this->assertStringContainsString('[ERROR] plainPassword ()', $output);
$this->assertStringContainsString('This value is too short. It should have 8 characters or more', $output);
$this->assertStringContainsString('[ERROR] email: This value should not be blank', $output);
$this->assertStringContainsString('[ERROR] plainPassword: This value should not be blank', $output);
$this->assertStringContainsString('[ERROR] plainPassword: This value is too short.', $output);
}
public function testUserAlreadyExisting()
public function testUserAlreadyExisting(): void
{
$this->createUser('MyTestUser', 'user@example.com', 'ROLE_USER', 'foobar123');
$commandTester = $this->createUser('MyTestUser', 'user2@example.com', 'ROLE_USER', 'foobar123');
$output = $commandTester->getDisplay();
$this->assertStringContainsString('[ERROR] username (MyTestUser)', $output);
$this->assertStringContainsString('The username is already used.', $output);
$this->assertStringContainsString('[ERROR] username: The username is already used.', $output);
}
public function testEmailAlreadyExisting()
public function testEmailAlreadyExisting(): void
{
$this->createUser('MyTestUser', 'user@example.com', 'ROLE_USER', 'foobar12');
$commandTester = $this->createUser('MyTestUser2', 'user@example.com', 'ROLE_USER', 'foobar');
$output = $commandTester->getDisplay();
$this->assertStringContainsString('[ERROR] email (MyTestUser2)', $output);
$this->assertStringContainsString(' The email is already used.', $output);
$this->assertStringContainsString('[ERROR] email: The email is already used.', $output);
}
public function testUserEmail()
public function testUserEmail(): void
{
$commandTester = $this->createUser('MyTestUser', 'ROLE_USER', 'ROLE_USER', 'foobar12');
$output = $commandTester->getDisplay();
$this->assertStringContainsString('[ERROR] email (ROLE_USER)', $output);
$this->assertStringContainsString('This value is not a valid email address', $output);
$this->assertStringContainsString('[ERROR] email: This value is not a valid email address', $output);
}
}