/**
  * Create Branch
  * @param Command\BranchCommand $branchCommand
  * @return \Diamante\DeskBundle\Entity\Branch
  */
 public function createBranch(Command\BranchCommand $branchCommand)
 {
     $this->isGranted('CREATE', 'Entity:DiamanteDeskBundle:Branch');
     $logo = $this->uploadBranchLogoIfExists($branchCommand);
     $assignee = $this->extractDefaultBranchAssignee($branchCommand);
     $branch = $this->branchFactory->create($branchCommand->name, $branchCommand->description, $branchCommand->key, $assignee, $logo, $branchCommand->tags);
     $this->registry->getManager()->persist($branch);
     $this->registry->getManager()->flush();
     $this->tagManager->saveTagging($branch);
     return $branch;
 }
 /**
  * Create Branch
  * @param Command\BranchCommand $branchCommand
  * @return \Diamante\DeskBundle\Model\Branch\Branch
  * @throws DuplicateBranchKeyException
  */
 public function createBranch(Command\BranchCommand $branchCommand)
 {
     $this->isGranted('CREATE', 'Entity:DiamanteDeskBundle:Branch');
     $logo = null;
     $originalName = null;
     if ($branchCommand->logoFile) {
         $logo = $this->handleLogoUpload($branchCommand->logoFile);
         $originalName = $branchCommand->logoFile->getClientOriginalName();
     }
     if ($branchCommand->defaultAssignee) {
         $assignee = $this->userService->getByUser(new User($branchCommand->defaultAssignee, User::TYPE_ORO));
     } else {
         $assignee = null;
     }
     $branch = $this->branchFactory->create($branchCommand->name, $branchCommand->description, $branchCommand->key, $assignee, $logo, $originalName, $branchCommand->tags);
     $this->branchRepository->store($branch);
     $this->tagManager->saveTagging($branch);
     return $branch;
 }
 public function testCreateWhenKeyIsNotDefined()
 {
     $this->branchKeyGenerator->expects($this->once())->method('generate')->with(self::NAME)->will($this->returnValue(self::KEY));
     $branch = $this->factory->create(self::NAME, self::DESCRIPTION);
     $this->assertEquals(self::KEY, $branch->getKey());
 }