public function execute(DeleteUrlRequest $request) { $url = $this->repository->findByUid($request->getUid()); if (!$url) { throw new UrlNotFoundException(); } if ($url->getDeleteToken() !== $request->getDeleteToken()) { throw new UrlDeleteTokenMismatchException(); } $this->repository->remove($url); return true; }
function it_throws_exception_when_found_url_but_delete_token_doesnt_match(UrlRepository $repository, Url $url) { $url->getDeleteToken()->willReturn('other_token'); $request = new DeleteUrlRequest('uid', 'delete_token'); $repository->findByUid('uid')->shouldBeCalled()->willReturn($url); $this->beConstructedWith($repository); $this->shouldThrow('Urleak\\Domain\\Command\\UrlDeleteTokenMismatchException')->during('execute', [$request]); }
/** * @param $uid * @return \Urleak\Domain\Model\Url|null */ public function isUsedUid($uid) { return null !== $this->repository->findByUid($uid); }