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_removes_existing_url_when_uid_and_delete_token_matches(UrlRepository $repository, Url $url) { $url->getUid()->willReturn('uid'); $url->getDeleteToken()->willReturn('delete_token'); $request = new DeleteUrlRequest('uid', 'delete_token'); $repository->findByUid('uid')->shouldBeCalled()->willReturn($url); $repository->remove($url)->shouldBeCalled(); $this->beConstructedWith($repository); $this->execute($request)->shouldReturn(true); }