application = new Application($kernel); $container = self::$kernel->getContainer(); $userService = $container->get(UserService::class); $this->application->add(new DeactivateUserCommand($userService)); } public function testCommandName(): void { $application = $this->application; $command = $application->find('kimai:user:deactivate'); self::assertInstanceOf(DeactivateUserCommand::class, $command); } protected function callCommand(?string $username): CommandTester { $command = $this->application->find('kimai:user:deactivate'); $input = [ 'command' => $command->getName(), ]; if ($username !== null) { $input['username'] = $username; } $commandTester = new CommandTester($command); $commandTester->execute($input); return $commandTester; } public function testDeactivate(): void { $commandTester = $this->callCommand('john_user'); $output = $commandTester->getDisplay(); $this->assertStringContainsString('[OK] User "john_user" has been deactivated.', $output); $container = self::$kernel->getContainer(); /** @var UserRepository $userRepository */ $userRepository = $container->get('doctrine')->getRepository(User::class); $user = $userRepository->loadUserByIdentifier('john_user'); self::assertInstanceOf(User::class, $user); self::assertFalse($user->isEnabled()); } public function testDeactivateOnDeactivatedUser(): void { $commandTester = $this->callCommand('chris_user'); $output = $commandTester->getDisplay(); $this->assertStringContainsString('[WARNING] User "chris_user" is already deactivated.', $output); } public function testWithMissingUsername(): void { $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Not enough arguments (missing: "username").'); $this->callCommand(null); } }