/**
  * Run installation in context of the specified admin user
  *
  * @param $userName
  * @param array $modules
  * @return void
  * @throws \Exception
  */
 public function run($userName, array $modules = [])
 {
     set_time_limit(0);
     /** @var \Magento\User\Model\User $user */
     $user = $this->userFactory->create()->loadByUsername($userName);
     if (!$user->getId()) {
         throw new \Exception('Invalid admin user provided');
     }
     $this->state->start();
     $this->session->setUser($user);
     $this->deploy->run();
     $resources = $this->initResources($modules);
     $this->state->clearErrorFlag();
     try {
         foreach ($this->moduleList->getNames() as $moduleName) {
             if (isset($resources[$moduleName])) {
                 $resourceType = $resources[$moduleName];
                 $this->setupFactory->create($resourceType)->run();
                 $this->postInstaller->addModule($moduleName);
             }
         }
         $this->session->unsUser();
         $this->postInstaller->run();
         $this->state->finish();
     } catch (\Exception $e) {
         $this->state->setError();
         $this->logger->log($e->getMessage());
     }
 }
 public function testIsInstallationErrorFalse()
 {
     $this->state->expects($this->once())->method('getState')->willReturn(\Magento\SampleData\Helper\State::STATE_NOT_STARTED);
     $this->assertFalse($this->sampleDataInstall->isInstallationError());
 }
 /**
  * Check whether there was unsuccessful attempt to install Sample data
  *
  * @return bool
  */
 public function isInstallationError()
 {
     return State::STATE_STARTED === $this->state->getState();
 }