/**
  * @test
  */
 public function createBranchWithAllValues()
 {
     $key = 'DB';
     $name = 'DUMMY_NAME';
     $description = 'DUMMY_DESC';
     $assigneeId = 1;
     $assignee = new User($assigneeId, User::TYPE_ORO);
     $defaultAssignee = new OroUser();
     $tags = array();
     $branch = new Branch($key, $name, $description, null, new Logo('dummy'));
     $this->fileMock = new UploadedFileStub(self::DUMMY_LOGO_PATH, self::DUMMY_LOGO_NAME);
     $logoMock = new Logo($this->fileMock->getFilename(), $this->fileMock->getClientOriginalName());
     $this->registry->expects($this->once())->method('getRepository')->with($this->equalTo('OroUserBundle:User'))->will($this->returnValue($this->userRepo));
     $this->userRepo->expects($this->once())->method('find')->with($this->equalTo($assigneeId))->will($this->returnValue($defaultAssignee));
     $this->branchLogoHandler->expects($this->once())->method('upload')->with($this->equalTo($this->fileMock))->will($this->returnValue($this->fileMock));
     $this->branchFactory->expects($this->once())->method('create')->with($this->equalTo($name), $this->equalTo($description), $key, $this->equalTo($defaultAssignee), $this->equalTo($logoMock))->will($this->returnValue($branch));
     $this->tagManager->expects($this->once())->method('saveTagging')->with($this->equalTo($branch));
     $this->registry->expects($this->exactly(2))->method('getManager')->will($this->returnValue($this->entityManager));
     $this->entityManager->expects($this->once())->method('persist')->with($branch);
     $this->entityManager->expects($this->once())->method('flush');
     $this->authorizationService->expects($this->once())->method('isActionPermitted')->with($this->equalTo('CREATE'), $this->equalTo('Entity:DiamanteDeskBundle:Branch'))->will($this->returnValue(true));
     $command = new BranchCommand();
     $command->key = $key;
     $command->name = $name;
     $command->description = $description;
     $command->defaultAssignee = $assigneeId;
     $command->tags = $tags;
     $command->logoFile = $this->fileMock;
     $this->branchServiceImpl->createBranch($command);
 }
 /**
  * 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());
 }