public function testCreateExceptionFromNonModuleRepository() { $exception = Exception\RepositoryException::fromNonModuleRepository('fooPublicMessage', 'foo/name'); $this->assertInstanceOf(Exception\RepositoryException::class, $exception); $this->assertSame('fooPublicMessage', $exception->getPublicMessage()); $this->assertSame('Invalid Repository - No ZF Module [foo/name]', $exception->getMessage()); $this->assertSame(Http\Response::STATUS_CODE_403, $exception->getCode()); }
/** * Register a new Module * * @return Http\Response * @throws Exception\InvalidDataException * @throws Exception\RepositoryException */ public function addAction() { 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...', $this->getRequest()); } $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 add this module. The reason might be that you are neither the owner nor a collaborator of this repository.', $repository->full_name, ['pushAccess', 'noFork']); } if (!$this->moduleService->isModule($repository)) { throw Exception\RepositoryException::fromNonModuleRepository($repository->name . ' is not a Zend Framework Module', $repository->full_name); } $module = $this->moduleService->register($repository); $this->flashMessenger()->addSuccessMessage($module->getName() . ' has been added to ZF Modules'); return $this->redirect()->toRoute('zfcuser'); }