public function testCreateExceptionFromStaticMethodInvalidRequest()
 {
     $requestMock = $this->getMock(Http\Request::class);
     $requestMock->expects($this->once())->method('toString')->willReturn('fooRequestAsString');
     $exception = Exception\InvalidDataException::fromInvalidRequest('fooPublicMessage', $requestMock);
     $this->assertInstanceOf(Exception\InvalidDataException::class, $exception);
     $this->assertSame('fooPublicMessage', $exception->getPublicMessage());
     $this->assertSame('Invalid Request received [fooRequestAsString]', $exception->getMessage());
 }
 /**
  * Removes a Module
  *
  * @return Http\Response
  * @throws Exception\InvalidDataException
  * @throws Exception\RepositoryException
  */
 public function removeAction()
 {
     if (!$this->zfcUserAuthentication()->hasIdentity()) {
         return $this->redirect()->toRoute('zfcuser/login');
     }
     $request = $this->getRequest();
     if (!$request->isPost()) {
         throw Exception\InvalidDataException::fromInvalidRequest('Something went wrong with the post values of the request...', $request);
     }
     $postParams = $request->getPost();
     $repo = $postParams->get('repo');
     $owner = $postParams->get('owner');
     $repository = $this->repositoryRetriever->getUserRepositoryMetadata($owner, $repo);
     if (!$repository instanceof \stdClass) {
         throw Exception\RepositoryException::fromNotFoundRepository('Not able to fetch the repository from GitHub due to an unknown error.', $owner, $repo);
     }
     if ($repository->fork || !$repository->permissions->push) {
         throw Exception\RepositoryException::fromInsufficientPermissions('You have no permission to remove this module. The reason might be that you are neither the owner nor a collaborator of this repository.', $repository->full_name, ['pushAccess', 'noFork']);
     }
     $module = $this->moduleMapper->findByUrl($repository->html_url);
     if (!$module) {
         throw Exception\RepositoryException::fromNotFoundRepositoryUrl($repository->name . ' was not found', $repository->html_url);
     }
     $this->moduleMapper->delete($module);
     $this->flashMessenger()->addSuccessMessage($repository->name . ' has been removed from ZF Modules');
     return $this->redirect()->toRoute('zfcuser');
 }