/** * @return AccountUser */ protected function getAccountUser() { $accountUser = new AccountUser(); /** @var WebsiteManager $websiteManager */ $websiteManager = $this->get('orob2b_website.manager'); $website = $websiteManager->getCurrentWebsite(); /** @var Organization|OrganizationInterface $websiteOrganization */ $websiteOrganization = $website->getOrganization(); if (!$websiteOrganization) { throw new \RuntimeException('Website organization is empty'); } $defaultRole = $this->getDoctrine()->getManagerForClass('OroB2BAccountBundle:AccountUserRole')->getRepository('OroB2BAccountBundle:AccountUserRole')->getDefaultAccountUserRoleByWebsite($website); if (!$defaultRole) { throw new \RuntimeException(sprintf('Role "%s" was not found', AccountUser::ROLE_DEFAULT)); } $accountUser->addOrganization($websiteOrganization)->setOrganization($websiteOrganization)->addRole($defaultRole); return $accountUser; }