/** * @param string $nom * @param User $owner * @return PageEleveur * @throws HistoryException */ public function create($nom, User $owner) { if ($this->pageEleveurBranchRepository->findByOwner($owner)) { $this->logger->notice('', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); throw new HistoryException(HistoryException::DEJA_OWNER); } $commit = new PageEleveurCommit(null, $nom, null, null, null, null, null, null); $pageEleveurBranch = new PageEleveurBranch(); $pageEleveurBranch->setCommit($commit); try { $pageEleveurBranch->setSlug(static::slug($nom)); } catch (InvalidArgumentException $e) { throw new HistoryException(HistoryException::NOM_INVALIDE); } $pageEleveurBranch->setOwner($owner); if ($this->pageEleveurBranchRepository->findBySlug($pageEleveurBranch->getSlug())) { throw new HistoryException(HistoryException::SLUG_DEJA_EXISTANT); } $this->doctrine->persist($pageEleveurBranch->getCommit()); $this->doctrine->persist($pageEleveurBranch); $this->doctrine->flush([$pageEleveurBranch->getCommit(), $pageEleveurBranch]); return $this->fromBranch($pageEleveurBranch); }
/** * @expectedException \AppBundle\Service\HistoryException * @expectedExceptionCode \AppBundle\Service\HistoryException::DROIT_REFUSE */ public function testCommit_pas_owner_droit_refuse() { // Simulation branche en bdd $user = new User(); $user->setId(1); $pageEleveurBranch = new PageEleveurBranch(); $pageEleveurBranch->setOwner($user); $commit = new PageEleveurCommit(null, '', null, null, null, null, null, null); $pageEleveurBranch->setCommit($commit); $this->pageEleveurBranchRepository->method('find')->willReturn($pageEleveurBranch); $this->pageEleveurCommitRepository->method('find')->with(10)->willReturn($commit); // Simulation commit $pageEleveur = new PageEleveur(); $user2 = new User(); $user2->setId(2); $pageEleveur->setHead(10); $this->pageEleveurService->commit($user2, $pageEleveur); }