From 2066a7f5112081b4bddfda67655f88f0a0bc3c76 Mon Sep 17 00:00:00 2001 From: MBorne Date: Sun, 25 Nov 2018 19:15:46 +0100 Subject: [PATCH] move out mborne/remote-git (closes #24) --- README.md | 2 +- composer.json | 5 +- composer.lock | 42 +++- src/MBO/RemoteGit/ClientFactory.php | 78 ------- src/MBO/RemoteGit/ClientInterface.php | 37 ---- src/MBO/RemoteGit/ClientOptions.php | 114 ---------- .../Filter/ComposerProjectFilter.php | 117 ----------- src/MBO/RemoteGit/Filter/FilterCollection.php | 91 -------- .../RemoteGit/Filter/IgnoreRegexpFilter.php | 45 ---- .../RemoteGit/Filter/RequiredFileFilter.php | 71 ------- src/MBO/RemoteGit/FindOptions.php | 157 -------------- src/MBO/RemoteGit/Github/GithubClient.php | 163 --------------- src/MBO/RemoteGit/Github/GithubProject.php | 57 ----- src/MBO/RemoteGit/Gitlab/GitlabClient.php | 195 ------------------ src/MBO/RemoteGit/Gitlab/GitlabProject.php | 57 ----- src/MBO/RemoteGit/ProjectFilterInterface.php | 27 --- src/MBO/RemoteGit/ProjectInterface.php | 43 ---- .../Command/GitlabToConfigCommandTest.php | 0 .../Command/expected-with-filter.json | 0 .../RemoteGit/Filter/FilterCollectionTest.php | 69 ------- .../Filter/IgnoreRegexpFilterTest.php | 39 ---- tests/RemoteGit/GithubClientTest.php | 125 ----------- tests/RemoteGit/GitlabClientTest.php | 104 ---------- .../Satis/ConfigBuilderTest.php | 0 .../Satis/expected-repositories.json | 0 tests/{SatisGitlab => }/TestCase.php | 0 26 files changed, 44 insertions(+), 1594 deletions(-) delete mode 100644 src/MBO/RemoteGit/ClientFactory.php delete mode 100644 src/MBO/RemoteGit/ClientInterface.php delete mode 100644 src/MBO/RemoteGit/ClientOptions.php delete mode 100644 src/MBO/RemoteGit/Filter/ComposerProjectFilter.php delete mode 100644 src/MBO/RemoteGit/Filter/FilterCollection.php delete mode 100644 src/MBO/RemoteGit/Filter/IgnoreRegexpFilter.php delete mode 100644 src/MBO/RemoteGit/Filter/RequiredFileFilter.php delete mode 100644 src/MBO/RemoteGit/FindOptions.php delete mode 100644 src/MBO/RemoteGit/Github/GithubClient.php delete mode 100644 src/MBO/RemoteGit/Github/GithubProject.php delete mode 100644 src/MBO/RemoteGit/Gitlab/GitlabClient.php delete mode 100644 src/MBO/RemoteGit/Gitlab/GitlabProject.php delete mode 100644 src/MBO/RemoteGit/ProjectFilterInterface.php delete mode 100644 src/MBO/RemoteGit/ProjectInterface.php rename tests/{SatisGitlab => }/Command/GitlabToConfigCommandTest.php (100%) rename tests/{SatisGitlab => }/Command/expected-with-filter.json (100%) delete mode 100644 tests/RemoteGit/Filter/FilterCollectionTest.php delete mode 100644 tests/RemoteGit/Filter/IgnoreRegexpFilterTest.php delete mode 100644 tests/RemoteGit/GithubClientTest.php delete mode 100644 tests/RemoteGit/GitlabClientTest.php rename tests/{SatisGitlab => }/Satis/ConfigBuilderTest.php (100%) rename tests/{SatisGitlab => }/Satis/expected-repositories.json (100%) rename tests/{SatisGitlab => }/TestCase.php (100%) diff --git a/README.md b/README.md index dfdce4f..7e3619a 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ Some command line options provide a basic customization options. You may also us PHP 7.2 version is recommanded as it is the current LTS with the longest support (see [PHP - Supported Versions](http://php.net/supported-versions.php)) -Meanwhile [7.1, 7.2 and 7.3 are tested throw Travis CI](https://travis-ci.org/mborne/satis-gitlab) +Meanwhile [5.6, 7.1, 7.2 and 7.3 are tested throw Travis CI](https://travis-ci.org/mborne/satis-gitlab) ## Testing diff --git a/composer.json b/composer.json index e1fc4d1..d0b3772 100644 --- a/composer.json +++ b/composer.json @@ -11,15 +11,14 @@ }, "autoload-dev": { "psr-4": { - "MBO\\SatisGitlab\\Tests\\": "tests/SatisGitlab", - "MBO\\RemoteGit\\Tests\\": "tests/RemoteGit" + "MBO\\SatisGitlab\\Tests\\": "tests" } }, "bin": [ "bin/satis-gitlab" ], "require": { - "guzzlehttp/guzzle": "~6.0", + "mborne/remote-git": "~0.1", "symfony/console": "^3.4", "composer/satis": "^1.0" }, diff --git a/composer.lock b/composer.lock index 11caefa..6af5bcf 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "07645bb24202490ad5671d5d118cbf55", + "content-hash": "b80856e2fc655174714db92728bd4227", "packages": [ { "name": "composer/ca-bundle", @@ -622,6 +622,46 @@ ], "time": "2018-02-14T22:26:30+00:00" }, + { + "name": "mborne/remote-git", + "version": "v0.1.0", + "source": { + "type": "git", + "url": "https://github.com/mborne/remote-git.git", + "reference": "4152921df81e1db53570234a23454348e58c95fd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mborne/remote-git/zipball/4152921df81e1db53570234a23454348e58c95fd", + "reference": "4152921df81e1db53570234a23454348e58c95fd", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "~6.0", + "psr/log": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "^5|^7" + }, + "bin": [ + "bin/satis-gitlab" + ], + "type": "library", + "autoload": { + "psr-4": { + "": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "authors": [ + { + "name": "Mickaƫl BORNE", + "email": "mborne@users.noreply.github.com" + } + ], + "description": "A lightweight PHP client providing a consistent way to find hosted and self-hosted git repositories (github, gitlab,...)", + "time": "2018-11-25T17:57:56+00:00" + }, { "name": "psr/http-message", "version": "1.0.1", diff --git a/src/MBO/RemoteGit/ClientFactory.php b/src/MBO/RemoteGit/ClientFactory.php deleted file mode 100644 index 6d80117..0000000 --- a/src/MBO/RemoteGit/ClientFactory.php +++ /dev/null @@ -1,78 +0,0 @@ -getUrl()); - - /* common http options */ - $guzzleOptions = array( - 'base_uri' => $options->getUrl(), - 'timeout' => 10.0, - 'headers' => [] - ); - if ( $options->isUnsafeSsl() ){ - $guzzleOptions['verify'] = false; - } - - /* Force github URL */ - if ( GithubClient::class === $clientClass ){ - $guzzleOptions['base_uri'] = 'https://api.github.com'; - } - - /* Define auth token */ - if ( $options->hasToken() ){ - if ( GitlabClient::class === $clientClass ){ - $guzzleOptions['headers']['Private-Token'] = $options->getToken(); - }else if ( GithubClient::class === $clientClass ){ - $guzzleOptions['headers']['Authorization'] = 'token '.$options->getToken(); - } - } - - $httpClient = new GuzzleHttpClient($guzzleOptions); - - /* create gitlab client */ - return new $clientClass($httpClient,$logger); - } - - /** - * Get client class according to URL content - * - * @param string $url - * @return string - */ - public static function detectClientClass($url){ - $hostname = parse_url($url, PHP_URL_HOST); - if ( 'api.github.com' === $hostname || 'github.com' === $hostname ){ - return GithubClient::class; - }else{ - return GitlabClient::class; - } - } - -} - diff --git a/src/MBO/RemoteGit/ClientInterface.php b/src/MBO/RemoteGit/ClientInterface.php deleted file mode 100644 index f9df667..0000000 --- a/src/MBO/RemoteGit/ClientInterface.php +++ /dev/null @@ -1,37 +0,0 @@ -unsafeSsl = false; - } - - /** - * @return string - */ - public function getUrl() - { - return $this->url; - } - - /** - * Set URL - * - * @param string $url - * - * @return self - */ - public function setUrl($url) - { - $this->url = $url; - - return $this; - } - - /** - * Is token defined? - * - * @return boolean - */ - public function hasToken(){ - return ! empty($this->token); - } - - /** - * Get access token - * - * @return string - */ - public function getToken() - { - return $this->token; - } - - /** - * Set access token - * - * @param string $token Access token - * - * @return self - */ - public function setToken($token) - { - $this->token = $token; - - return $this; - } - - /** - * @return boolean - */ - public function isUnsafeSsl() - { - return $this->unsafeSsl; - } - - /** - * Set unsafeSsl - * - * @param boolean $unsafeSsl - * - * @return self - */ - public function setUnsafeSsl($unsafeSsl) - { - $this->unsafeSsl = $unsafeSsl; - - return $this; - } -} diff --git a/src/MBO/RemoteGit/Filter/ComposerProjectFilter.php b/src/MBO/RemoteGit/Filter/ComposerProjectFilter.php deleted file mode 100644 index 7ca4031..0000000 --- a/src/MBO/RemoteGit/Filter/ComposerProjectFilter.php +++ /dev/null @@ -1,117 +0,0 @@ -gitClient = $gitClient; - $this->logger = $logger; - } - - /** - * Get filter according to project type - * - * @return string - */ - public function getProjectType() - { - return $this->projectType; - } - - /** - * Set filter according to project type - * - * @param string $projectType Filter according to project type - * - * @return self - */ - public function setProjectType(string $projectType) - { - $this->projectType = $projectType; - - return $this; - } - - - /** - * {@inheritDoc} - */ - public function getDescription(){ - $description = "composer.json should exists"; - if ( ! empty($this->projectType) ){ - $description .= sprintf(" and type should be '%s'",$this->projectType); - } - return $description; - } - - /** - * {@inheritDoc} - */ - public function isAccepted(ProjectInterface $project) - { - try { - $json = $this->gitClient->getRawFile( - $project, - 'composer.json', - $project->getDefaultBranch() - ); - $composer = json_decode($json, true); - if ( empty($this->projectType) ){ - return true; - } - return isset($composer['type']) - && strtolower($composer['type']) === strtolower($this->projectType) - ; - }catch(\Exception $e){ - $this->logger->debug(sprintf( - '%s (branch %s) : file %s not found', - $project->getName(), - $project->getDefaultBranch(), - 'composer.json' - )); - return false; - } - } - - - -} diff --git a/src/MBO/RemoteGit/Filter/FilterCollection.php b/src/MBO/RemoteGit/Filter/FilterCollection.php deleted file mode 100644 index 345dc32..0000000 --- a/src/MBO/RemoteGit/Filter/FilterCollection.php +++ /dev/null @@ -1,91 +0,0 @@ -filters = array(); - $this->logger = is_null($logger) ? new NullLogger() : $logger; - } - - /** - * Add a filter to the collection - * - * @param ProjectFilterInterface $filter - * @return void - */ - public function addFilter(ProjectFilterInterface $filter){ - $this->filters[] = $filter; - } - - /** - * {@inheritDoc} - */ - public function getDescription(){ - $parts = array(); - foreach ( $this->filters as $filter ){ - $parts[] = ' - '.$filter->getDescription(); - } - return implode(PHP_EOL,$parts); - } - - /** - * {@inheritDoc} - */ - public function isAccepted(ProjectInterface $project){ - foreach ( $this->filters as $filter ){ - if ( ! $filter->isAccepted($project) ){ - $this->logger->info(sprintf( - "[%s]Ignoring project %s (%s)", - $this->getFilterName($filter), - $project->getName(), - $filter->getDescription() - )); - return false; - } - } - $this->logger->debug(sprintf( - "[FilterCollection]keep project %s", - $project->getName() - )); - return true; - } - - /** - * Get filter name - * - * @param ProjectFilterInterface $filter - * @return string - */ - private function getFilterName(ProjectFilterInterface $filter){ - $clazz = get_class($filter); - $parts = explode('\\',$clazz); - return $parts[count($parts)-1]; - } -} - diff --git a/src/MBO/RemoteGit/Filter/IgnoreRegexpFilter.php b/src/MBO/RemoteGit/Filter/IgnoreRegexpFilter.php deleted file mode 100644 index 4964662..0000000 --- a/src/MBO/RemoteGit/Filter/IgnoreRegexpFilter.php +++ /dev/null @@ -1,45 +0,0 @@ -ignoreRegexp = $ignoreRegexp; - } - - /** - * {@inheritDoc} - */ - public function getDescription(){ - return "project name should not match /".$this->ignoreRegexp+"/"; - } - - /** - * {@inheritDoc} - */ - public function isAccepted(ProjectInterface $project) - { - if ( preg_match("/$this->ignoreRegexp/", $project->getName() ) ){ - return false; - }else{ - return true; - } - } - -} diff --git a/src/MBO/RemoteGit/Filter/RequiredFileFilter.php b/src/MBO/RemoteGit/Filter/RequiredFileFilter.php deleted file mode 100644 index 77a51d6..0000000 --- a/src/MBO/RemoteGit/Filter/RequiredFileFilter.php +++ /dev/null @@ -1,71 +0,0 @@ -gitClient = $gitClient; - $this->filePath = $filePath; - $this->logger = $logger; - } - - /** - * {@inheritDoc} - */ - public function getDescription(){ - return sprintf("File '%s' should exist in default branch",$this->filePath); - } - - - /** - * {@inheritDoc} - */ - public function isAccepted(ProjectInterface $project) - { - try { - $this->gitClient->getRawFile( - $project, - $this->filePath, - $project->getDefaultBranch() - ); - return true; - }catch(\Exception $e){ - $this->logger->debug(sprintf( - '%s (branch %s) : file %s not found', - $project->getName(), - $project->getDefaultBranch(), - $this->filePath - )); - return false; - } - } - -} diff --git a/src/MBO/RemoteGit/FindOptions.php b/src/MBO/RemoteGit/FindOptions.php deleted file mode 100644 index e9bb4ac..0000000 --- a/src/MBO/RemoteGit/FindOptions.php +++ /dev/null @@ -1,157 +0,0 @@ -filter = new FilterCollection(); - } - - /** - * True if search is defined - * - * @return boolean - */ - public function hasSearch(){ - return ! empty($this->search); - } - - /** - * Get search string (prefer the use of organizations and users) - * - * @return string - */ - public function getSearch() - { - return $this->search; - } - - /** - * Set search string (prefer the use of organizations and users) - * - * @param string $search Search string (prefer the use of organizations and users) - * - * @return self - */ - public function setSearch($search) - { - $this->search = $search; - - return $this; - } - - - - /** - * Get filter according to organizations - * - * @return string[] - */ - public function getOrganizations() - { - return $this->organizations; - } - - /** - * Set filter according to organizations - * - * @param string[] $organizations Filter according to organizations - * - * @return self - */ - public function setOrganizations(array $organizations) - { - $this->organizations = $organizations; - - return $this; - } - - - /** - * Get filter according to user names - * - * @return string[] - */ - public function getUsers() - { - return $this->users; - } - - /** - * Set filter according to user names - * - * @param string[] $users Filter according to user names - * - * @return self - */ - public function setUsers(array $users) - { - $this->users = $users; - - return $this; - } - - - /** - * Get project listing API parameters - * - * @return ProjectFilterInterface - */ - public function getFilter() - { - return $this->filter; - } - - /** - * Set project listing API parameters - * - * @param ProjectFilterInterface $filter project listing API parameters - * - * @return self - */ - public function setFilter(ProjectFilterInterface $filter) - { - $this->filter = $filter; - - return $this; - } - -} \ No newline at end of file diff --git a/src/MBO/RemoteGit/Github/GithubClient.php b/src/MBO/RemoteGit/Github/GithubClient.php deleted file mode 100644 index e0f1f56..0000000 --- a/src/MBO/RemoteGit/Github/GithubClient.php +++ /dev/null @@ -1,163 +0,0 @@ -httpClient = $httpClient ; - $this->logger = $logger ; - } - - /* - * @{inheritDoc} - */ - public function find(FindOptions $options){ - $result = array(); - if ( empty($options->getUsers()) && empty($options->getOrganizations()) ){ - throw new \Exception("[GithubClient]Define at least an org or a user to use find"); - } - foreach ( $options->getUsers() as $user ){ - $result = array_merge($result,$this->findByUser( - $user, - $options->getFilter() - )); - } - foreach ( $options->getOrganizations() as $org ){ - $result = array_merge($result,$this->findByOrg( - $org, - $options->getFilter() - )); - } - return $result; - } - - /** - * Find projects by username - * - * @return void - */ - protected function findByUser( - $user, - ProjectFilterInterface $projectFilter - ){ - return $this->fetchAllPages( - '/users/'.$user.'/repos', - $projectFilter - ); - } - - /** - * Find projects by username - * - * @return void - */ - protected function findByOrg( - $org, - ProjectFilterInterface $projectFilter - ){ - return $this->fetchAllPages( - '/orgs/'.$org.'/repos', - $projectFilter - ); - } - - /** - * Fetch all pages for a given URI - * - * @param string $path such as '/orgs/IGNF/repos' or '/users/mborne/repos' - * @return ProjectInterface[] - */ - private function fetchAllPages( - $path, - ProjectFilterInterface $projectFilter - ){ - $result = array(); - for ($page = 1; $page <= self::MAX_PAGES; $page++) { - $uri = $path.'?page='.$page.'&per_page='.self::DEFAULT_PER_PAGE; - - $this->logger->debug('GET '.$uri); - $response = $this->httpClient->get($uri); - $rawProjects = json_decode( (string)$response->getBody(), true ) ; - if ( empty($rawProjects) ){ - break; - } - foreach ( $rawProjects as $rawProject ){ - $project = new GithubProject($rawProject); - if ( ! $projectFilter->isAccepted($project) ){ - continue; - } - $result[] = $project; - } - } - return $result; - } - - /* - * @{inheritDoc} - */ - public function getRawFile( - ProjectInterface $project, - $filePath, - $ref - ){ - $metadata = $project->getRawMetadata(); - $uri = str_replace( - '{+path}', - urlencode($filePath), - $metadata['contents_url'] - ); - $uri .= '?ref='.$ref; - $this->logger->debug('GET '.$uri); - $response = $this->httpClient->get($uri,[ - 'headers' => [ - 'Accept' => 'application/vnd.github.v3.raw' - ] - ]); - return (string)$response->getBody(); - } - - -} \ No newline at end of file diff --git a/src/MBO/RemoteGit/Github/GithubProject.php b/src/MBO/RemoteGit/Github/GithubProject.php deleted file mode 100644 index d1d7457..0000000 --- a/src/MBO/RemoteGit/Github/GithubProject.php +++ /dev/null @@ -1,57 +0,0 @@ -rawMetadata = $rawMetadata; - } - - /* - * @{inheritDoc} - */ - public function getId(){ - return $this->rawMetadata['id']; - } - - /* - * @{inheritDoc} - */ - public function getName(){ - return $this->rawMetadata['full_name']; - } - - /* - * @{inheritDoc} - */ - public function getDefaultBranch(){ - return $this->rawMetadata['default_branch']; - } - - /* - * @{inheritDoc} - */ - public function getHttpUrl(){ - return $this->rawMetadata['clone_url']; - } - - /* - * @{inheritDoc} - */ - public function getRawMetadata(){ - return $this->rawMetadata; - } - - -} diff --git a/src/MBO/RemoteGit/Gitlab/GitlabClient.php b/src/MBO/RemoteGit/Gitlab/GitlabClient.php deleted file mode 100644 index 628eb91..0000000 --- a/src/MBO/RemoteGit/Gitlab/GitlabClient.php +++ /dev/null @@ -1,195 +0,0 @@ -httpClient = $httpClient ; - $this->logger = $logger ; - } - - /* - * @{inheritDoc} - */ - public function find(FindOptions $options){ - /* find all projects applying optional search */ - if ( empty($options->getUsers()) && empty($options->getOrganizations()) ){ - return $this->findBySearch($options); - } - - $result = array(); - foreach ( $options->getUsers() as $user ){ - $result = array_merge($result,$this->findByUser( - $user, - $options->getFilter() - )); - } - foreach ( $options->getOrganizations() as $org ){ - $result = array_merge($result,$this->findByGroup( - $org, - $options->getFilter() - )); - } - return $result; - } - - /** - * Find projects by username - * - * @return void - */ - protected function findByUser( - $user, - ProjectFilterInterface $projectFilter - ){ - return $this->fetchAllPages( - '/api/v4/users/'.urlencode($user).'/projects', - array(), - $projectFilter - ); - } - - /** - * Find projects by group - * - * @return void - */ - protected function findByGroup( - $group, - ProjectFilterInterface $projectFilter - ){ - return $this->fetchAllPages( - '/api/v4/groups/'.urlencode($group).'/projects', - array(), - $projectFilter - ); - } - - /** - * Find all projects using option search - */ - protected function findBySearch(FindOptions $options){ - $path = '/api/v4/projects'; - $params = array(); - if ( $options->hasSearch() ){ - $params['search'] = $options->getSearch(); - } - return $this->fetchAllPages( - $path, - $params, - $options->getFilter() - ); - } - - - /** - * Fetch all pages for a given path with query params - * - * @param string $path ex : "/api/v4/projects" - * @param array $params ex : array('search'=>'sample-composer') - * @param ProjectFilterInterface $projectFilter - * @return ProjectInterface[] - */ - private function fetchAllPages( - $path, - array $params = array(), - ProjectFilterInterface $projectFilter - ){ - $result = array(); - - for ($page = 1; $page <= self::MAX_PAGES; $page++) { - $params['page'] = $page; - $params['per_page'] = self::DEFAULT_PER_PAGE; - $uri = $path.'?'.$this->implodeParams($params); - $this->logger->debug('GET '.$uri); - $response = $this->httpClient->get($uri); - $rawProjects = json_decode( (string)$response->getBody(), true ) ; - if ( empty($rawProjects) ){ - break; - } - foreach ( $rawProjects as $rawProject ){ - $project = new GitlabProject($rawProject); - if ( ! $projectFilter->isAccepted($project) ){ - continue; - } - $result[] = $project; - } - } - - return $result; - } - - /** - * Implode params to performs request - * - * @param array $params key=>value - * @return string - */ - private function implodeParams($params){ - $parts = array(); - foreach ( $params as $key => $value ){ - $parts[] = $key.'='.urlencode($value); - } - return implode('&',$parts); - } - - /* - * @{inheritDoc} - */ - public function getRawFile( - ProjectInterface $project, - $filePath, - $ref - ){ - // ref : https://docs.gitlab.com/ee/api/repository_files.html#get-raw-file-from-repository - $uri = '/api/v4/projects/'.$project->getId().'/repository/files/'.urlencode($filePath).'/raw'; - $uri .= '?ref='.$ref; - $this->logger->debug('GET '.$uri); - $response = $this->httpClient->get($uri); - return (string)$response->getBody(); - } - - -} \ No newline at end of file diff --git a/src/MBO/RemoteGit/Gitlab/GitlabProject.php b/src/MBO/RemoteGit/Gitlab/GitlabProject.php deleted file mode 100644 index bbe4a07..0000000 --- a/src/MBO/RemoteGit/Gitlab/GitlabProject.php +++ /dev/null @@ -1,57 +0,0 @@ -rawMetadata = $rawMetadata; - } - - /* - * @{inheritDoc} - */ - public function getId(){ - return $this->rawMetadata['id']; - } - - /* - * @{inheritDoc} - */ - public function getName(){ - return $this->rawMetadata['path_with_namespace']; - } - - /* - * @{inheritDoc} - */ - public function getDefaultBranch(){ - return $this->rawMetadata['default_branch']; - } - - /* - * @{inheritDoc} - */ - public function getHttpUrl(){ - return $this->rawMetadata['http_url_to_repo']; - } - - /* - * @{inheritDoc} - */ - public function getRawMetadata(){ - return $this->rawMetadata; - } - - -} diff --git a/src/MBO/RemoteGit/ProjectFilterInterface.php b/src/MBO/RemoteGit/ProjectFilterInterface.php deleted file mode 100644 index 39f1799..0000000 --- a/src/MBO/RemoteGit/ProjectFilterInterface.php +++ /dev/null @@ -1,27 +0,0 @@ -createMockProject('test'); - $this->assertTrue($filterCollection->isAccepted($project)); - } - - /** - * Create a fake project filter returning true or false - * - * @param boolean $accepted - * @return ProjectFilterInterface - */ - private function createMockFilter($accepted){ - $filter = $this->getMockBuilder(ProjectFilterInterface::class) - ->getMock() - ; - $filter->expects($this->any()) - ->method('isAccepted') - ->willReturn($accepted) - ; - return $filter; - } - - - public function testOneTrue(){ - $filterCollection = new FilterCollection(new NullLogger()); - $filterCollection->addFilter($this->createMockFilter(true)); - $project = $this->createMockProject('test'); - $this->assertTrue($filterCollection->isAccepted($project)); - } - - public function testOneFalse(){ - $filterCollection = new FilterCollection(new NullLogger()); - $filterCollection->addFilter($this->createMockFilter(false)); - $project = $this->createMockProject('test'); - $this->assertFalse($filterCollection->isAccepted($project)); - } - - /** - * Check that isAccepted is unanymous - */ - public function testTrueFalseTrue(){ - $filterCollection = new FilterCollection(new NullLogger()); - $filterCollection->addFilter($this->createMockFilter(true)); - $filterCollection->addFilter($this->createMockFilter(false)); - $filterCollection->addFilter($this->createMockFilter(true)); - $project = $this->createMockProject('test'); - $this->assertFalse($filterCollection->isAccepted($project)); - } - -} - diff --git a/tests/RemoteGit/Filter/IgnoreRegexpFilterTest.php b/tests/RemoteGit/Filter/IgnoreRegexpFilterTest.php deleted file mode 100644 index 87d1b16..0000000 --- a/tests/RemoteGit/Filter/IgnoreRegexpFilterTest.php +++ /dev/null @@ -1,39 +0,0 @@ - true, - 'something' => true, - 'meuh' => true, - 'phpstorm/something' => false - ); - - foreach ( $expectedResults as $projectName => $expected ){ - $project = $this->createMockProject($projectName); - $this->assertTrue( - $filter->isAccepted($project) === $expected, - 'unexpected result for '.$projectName - ); - } - - } - -} - diff --git a/tests/RemoteGit/GithubClientTest.php b/tests/RemoteGit/GithubClientTest.php deleted file mode 100644 index fb4b8f4..0000000 --- a/tests/RemoteGit/GithubClientTest.php +++ /dev/null @@ -1,125 +0,0 @@ -markTestSkipped("Missing SATIS_GITHUB_TOKEN for github.com"); - } - - $clientOptions = new ClientOptions(); - $clientOptions - ->setUrl('https://github.com') - ->setToken($token) - ; - - /* create client */ - return ClientFactory::createClient( - $clientOptions, - new NullLogger() - ); - } - - /** - * Ensure client can find mborne's projects - */ - public function testUserRepositories(){ - /* create client */ - $client = $this->createGithubClient(); - $this->assertInstanceOf(GithubClient::class,$client); - - /* search projects */ - $options = new FindOptions(); - $options->setUsers(array('mborne')); - $projects = $client->find($options); - $projectsByName = array(); - foreach ( $projects as $project ){ - $this->assertInstanceOf(GithubProject::class,$project); - $projectsByName[$project->getName()] = $project; - } - - /* check project found */ - $this->assertArrayHasKey( - 'mborne/satis-gitlab', - $projectsByName - ); - - $project = $projectsByName['mborne/satis-gitlab']; - $composer = $client->getRawFile( - $project, - 'composer.json', - $project->getDefaultBranch() - ); - $this->assertContains('mborne@users.noreply.github.com',$composer); - - $testFileInSubdirectory = $client->getRawFile( - $project, - 'tests/TestCase.php', - $project->getDefaultBranch() - ); - $this->assertContains('class TestCase',$testFileInSubdirectory); - } - - - /** - * Ensure client can find mborne's projects with composer.json file - */ - public function testFilterFile(){ - /* create client */ - $client = $this->createGithubClient(); - $this->assertInstanceOf(GithubClient::class,$client); - - /* search projects */ - $options = new FindOptions(); - $options->setUsers(array('mborne')); - $projects = $client->find($options); - $projectsByName = array(); - foreach ( $projects as $project ){ - $this->assertInstanceOf(GithubProject::class,$project); - $projectsByName[$project->getName()] = $project; - } - - /* check project found */ - $this->assertArrayHasKey( - 'mborne/satis-gitlab', - $projectsByName - ); - - $project = $projectsByName['mborne/satis-gitlab']; - $composer = $client->getRawFile( - $project, - 'composer.json', - $project->getDefaultBranch() - ); - $this->assertContains('mborne@users.noreply.github.com',$composer); - - $testFileInSubdirectory = $client->getRawFile( - $project, - 'tests/TestCase.php', - $project->getDefaultBranch() - ); - $this->assertContains('class TestCase',$testFileInSubdirectory); - } - - -} diff --git a/tests/RemoteGit/GitlabClientTest.php b/tests/RemoteGit/GitlabClientTest.php deleted file mode 100644 index adc4102..0000000 --- a/tests/RemoteGit/GitlabClientTest.php +++ /dev/null @@ -1,104 +0,0 @@ -markTestSkipped("Missing SATIS_GITLAB_TOKEN for gitlab.com"); - } - - $clientOptions = new ClientOptions(); - $clientOptions - ->setUrl('https://gitlab.com') - ->setToken($gitlabToken) - ; - - /* create client */ - return ClientFactory::createClient( - $clientOptions, - new NullLogger() - ); - } - - /** - * Ensure client can find mborne/sample-composer by username - */ - public function testGitlabDotComByUser(){ - /* create client */ - $client = $this->createGitlabClient(); - $this->assertInstanceOf(GitlabClient::class,$client); - - /* search projects */ - $findOptions = new FindOptions(); - $findOptions->setUsers(array('mborne')); - $projects = $client->find($findOptions); - $projectsByName = array(); - foreach ( $projects as $project ){ - $projectsByName[$project->getName()] = $project; - } - /* check project found */ - $this->assertArrayHasKey( - 'mborne/sample-composer', - $projectsByName - ); - - $project = $projectsByName['mborne/sample-composer']; - $composer = $client->getRawFile( - $project, - 'composer.json', - $project->getDefaultBranch() - ); - $this->assertContains('mborne@users.noreply.github.com',$composer); - } - - - /** - * Ensure client can find mborne/sample-composer with search - */ - public function testGitlabDotComSearch(){ - /* create client */ - $client = $this->createGitlabClient(); - $this->assertInstanceOf(GitlabClient::class,$client); - - /* search projects */ - $findOptions = new FindOptions(); - $findOptions->setSearch('sample-composer'); - $projects = $client->find($findOptions); - $projectsByName = array(); - foreach ( $projects as $project ){ - $projectsByName[$project->getName()] = $project; - } - /* check project found */ - $this->assertArrayHasKey( - 'mborne/sample-composer', - $projectsByName - ); - - $project = $projectsByName['mborne/sample-composer']; - $composer = $client->getRawFile( - $project, - 'composer.json', - $project->getDefaultBranch() - ); - $this->assertContains('mborne@users.noreply.github.com',$composer); - } - -} diff --git a/tests/SatisGitlab/Satis/ConfigBuilderTest.php b/tests/Satis/ConfigBuilderTest.php similarity index 100% rename from tests/SatisGitlab/Satis/ConfigBuilderTest.php rename to tests/Satis/ConfigBuilderTest.php diff --git a/tests/SatisGitlab/Satis/expected-repositories.json b/tests/Satis/expected-repositories.json similarity index 100% rename from tests/SatisGitlab/Satis/expected-repositories.json rename to tests/Satis/expected-repositories.json diff --git a/tests/SatisGitlab/TestCase.php b/tests/TestCase.php similarity index 100% rename from tests/SatisGitlab/TestCase.php rename to tests/TestCase.php