You are here

protected function TestSiteUserLoginCommand::execute in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/TestSite/Commands/TestSiteUserLoginCommand.php \Drupal\TestSite\Commands\TestSiteUserLoginCommand::execute()

Throws

\Symfony\Component\Console\Exception\InvalidArgumentException

File

core/tests/Drupal/TestSite/Commands/TestSiteUserLoginCommand.php, line 44

Class

TestSiteUserLoginCommand
Command to generate a login link for the test site.

Namespace

Drupal\TestSite\Commands

Code

protected function execute(InputInterface $input, OutputInterface $output) {
  $root = dirname(dirname(dirname(dirname(dirname(__DIR__)))));
  chdir($root);
  $this->classLoader = (require 'autoload.php');
  $kernel = new DrupalKernel('prod', $this->classLoader, FALSE);
  $kernel::bootEnvironment();
  $kernel
    ->setSitePath($input
    ->getOption('site-path'));
  Settings::initialize($kernel
    ->getAppRoot(), $kernel
    ->getSitePath(), $this->classLoader);
  $request = Request::createFromGlobals();
  $kernel
    ->boot();
  $kernel
    ->preHandle($request);
  $container = $kernel
    ->getContainer();
  $uid = $input
    ->getArgument('uid');
  if (!is_numeric($uid)) {
    throw new InvalidArgumentException(sprintf('The "uid" argument needs to be an integer, but it is "%s".', $uid));
  }
  $userEntity = $container
    ->get('entity_type.manager')
    ->getStorage('user')
    ->load($uid);
  $url = user_pass_reset_url($userEntity) . '/login';
  $output
    ->writeln($url);
  return 0;
}