2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2012-03-10 07:49:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Repository\Vcs;
|
|
|
|
|
|
|
|
use Composer\Repository\Vcs\GitHubDriver;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2012-03-15 17:32:31 +00:00
|
|
|
use Composer\Util\Filesystem;
|
2012-04-25 15:35:47 +00:00
|
|
|
use Composer\Config;
|
2021-08-19 11:00:30 +00:00
|
|
|
use Composer\Util\ProcessExecutor;
|
2012-03-10 07:49:21 +00:00
|
|
|
|
2016-01-21 12:01:55 +00:00
|
|
|
class GitHubDriverTest extends TestCase
|
2012-03-10 07:49:21 +00:00
|
|
|
{
|
2021-10-27 13:29:52 +00:00
|
|
|
/** @var string */
|
2016-01-21 12:01:55 +00:00
|
|
|
private $home;
|
2021-10-27 13:29:52 +00:00
|
|
|
/** @var Config */
|
2012-05-13 19:40:42 +00:00
|
|
|
private $config;
|
|
|
|
|
2021-12-08 16:03:05 +00:00
|
|
|
public function setUp(): void
|
2012-05-13 19:40:42 +00:00
|
|
|
{
|
2022-05-11 14:05:35 +00:00
|
|
|
$this->home = self::getUniqueTmpDirectory();
|
2012-05-13 19:40:42 +00:00
|
|
|
$this->config = new Config();
|
2022-08-17 12:20:07 +00:00
|
|
|
$this->config->merge([
|
|
|
|
'config' => [
|
2016-01-21 12:01:55 +00:00
|
|
|
'home' => $this->home,
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
]);
|
2012-05-13 19:40:42 +00:00
|
|
|
}
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
protected function tearDown(): void
|
2012-11-10 20:54:23 +00:00
|
|
|
{
|
2021-12-09 16:09:07 +00:00
|
|
|
parent::tearDown();
|
2012-11-10 20:54:23 +00:00
|
|
|
$fs = new Filesystem;
|
2016-01-21 12:01:55 +00:00
|
|
|
$fs->removeDirectory($this->home);
|
2012-11-10 20:54:23 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testPrivateRepository(): void
|
2012-03-10 07:49:21 +00:00
|
|
|
{
|
|
|
|
$repoUrl = 'http://github.com/composer/packagist';
|
2012-05-31 14:03:25 +00:00
|
|
|
$repoApiUrl = 'https://api.github.com/repos/composer/packagist';
|
2012-03-10 07:49:21 +00:00
|
|
|
$repoSshUrl = 'git@github.com:composer/packagist.git';
|
|
|
|
$identifier = 'v0.0.0';
|
|
|
|
$sha = 'SOMESHA';
|
|
|
|
|
2018-04-12 08:24:56 +00:00
|
|
|
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
2012-03-10 07:49:21 +00:00
|
|
|
$io->expects($this->any())
|
|
|
|
->method('isInteractive')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$httpDownloader = $this->getHttpDownloaderMock($io, $this->config);
|
|
|
|
$httpDownloader->expects(
|
|
|
|
[
|
|
|
|
['url' => $repoApiUrl, 'status' => 404],
|
|
|
|
['url' => 'https://api.github.com/', 'body' => '{}'],
|
|
|
|
['url' => $repoApiUrl, 'body' => '{"master_branch": "test_master", "private": true, "owner": {"login": "composer"}, "name": "packagist"}'],
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
2012-03-10 07:49:21 +00:00
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$process = $this->getProcessExecutorMock();
|
2022-08-17 12:20:07 +00:00
|
|
|
$process->expects([], false, ['return' => 1]);
|
2012-06-27 16:28:49 +00:00
|
|
|
|
2012-03-10 07:49:21 +00:00
|
|
|
$io->expects($this->once())
|
|
|
|
->method('askAndHideAnswer')
|
2015-05-06 23:37:08 +00:00
|
|
|
->with($this->equalTo('Token (hidden): '))
|
|
|
|
->will($this->returnValue('sometoken'));
|
2012-03-10 07:49:21 +00:00
|
|
|
|
2012-10-18 16:43:31 +00:00
|
|
|
$io->expects($this->any())
|
2012-11-07 12:33:50 +00:00
|
|
|
->method('setAuthentication')
|
2015-05-06 23:37:08 +00:00
|
|
|
->with($this->equalTo('github.com'), $this->matchesRegularExpression('{sometoken}'), $this->matchesRegularExpression('{x-oauth-basic}'));
|
2012-03-10 07:49:21 +00:00
|
|
|
|
2018-04-12 08:24:56 +00:00
|
|
|
$configSource = $this->getMockBuilder('Composer\Config\ConfigSourceInterface')->getMock();
|
|
|
|
$authConfigSource = $this->getMockBuilder('Composer\Config\ConfigSourceInterface')->getMock();
|
2012-10-18 16:43:31 +00:00
|
|
|
$this->config->setConfigSource($configSource);
|
2014-05-27 11:50:47 +00:00
|
|
|
$this->config->setAuthConfigSource($authConfigSource);
|
2012-03-10 07:49:21 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$repoConfig = [
|
2012-08-31 06:12:20 +00:00
|
|
|
'url' => $repoUrl,
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2012-08-31 06:12:20 +00:00
|
|
|
|
2018-11-12 14:34:54 +00:00
|
|
|
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $process);
|
2012-03-10 07:49:21 +00:00
|
|
|
$gitHubDriver->initialize();
|
2022-08-17 12:20:07 +00:00
|
|
|
$this->setAttribute($gitHubDriver, 'tags', [$identifier => $sha]);
|
2012-03-10 07:49:21 +00:00
|
|
|
|
|
|
|
$this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
|
|
|
|
|
|
|
|
$dist = $gitHubDriver->getDist($sha);
|
2022-11-03 20:47:26 +00:00
|
|
|
self::assertIsArray($dist);
|
2012-03-10 07:49:21 +00:00
|
|
|
$this->assertEquals('zip', $dist['type']);
|
2013-08-18 21:03:48 +00:00
|
|
|
$this->assertEquals('https://api.github.com/repos/composer/packagist/zipball/SOMESHA', $dist['url']);
|
|
|
|
$this->assertEquals('SOMESHA', $dist['reference']);
|
2012-03-10 07:49:21 +00:00
|
|
|
|
|
|
|
$source = $gitHubDriver->getSource($sha);
|
|
|
|
$this->assertEquals('git', $source['type']);
|
|
|
|
$this->assertEquals($repoSshUrl, $source['url']);
|
2013-08-18 21:03:48 +00:00
|
|
|
$this->assertEquals('SOMESHA', $source['reference']);
|
2012-03-10 07:49:21 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testPublicRepository(): void
|
2012-03-10 07:49:21 +00:00
|
|
|
{
|
|
|
|
$repoUrl = 'http://github.com/composer/packagist';
|
2012-05-31 14:03:25 +00:00
|
|
|
$repoApiUrl = 'https://api.github.com/repos/composer/packagist';
|
2012-03-10 07:49:21 +00:00
|
|
|
$identifier = 'v0.0.0';
|
|
|
|
$sha = 'SOMESHA';
|
|
|
|
|
2018-04-12 08:24:56 +00:00
|
|
|
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
2012-03-10 07:49:21 +00:00
|
|
|
$io->expects($this->any())
|
|
|
|
->method('isInteractive')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$httpDownloader = $this->getHttpDownloaderMock($io, $this->config);
|
|
|
|
$httpDownloader->expects(
|
|
|
|
[
|
|
|
|
['url' => $repoApiUrl, 'body' => '{"master_branch": "test_master", "owner": {"login": "composer"}, "name": "packagist"}'],
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
2012-03-10 07:49:21 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$repoConfig = [
|
2012-08-31 06:12:20 +00:00
|
|
|
'url' => $repoUrl,
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2013-02-13 11:59:16 +00:00
|
|
|
$repoUrl = 'https://github.com/composer/packagist.git';
|
2012-08-31 06:12:20 +00:00
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $this->getProcessExecutorMock());
|
2012-03-10 07:49:21 +00:00
|
|
|
$gitHubDriver->initialize();
|
2022-08-17 12:20:07 +00:00
|
|
|
$this->setAttribute($gitHubDriver, 'tags', [$identifier => $sha]);
|
2012-03-10 07:49:21 +00:00
|
|
|
|
|
|
|
$this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
|
|
|
|
|
|
|
|
$dist = $gitHubDriver->getDist($sha);
|
2022-11-03 20:47:26 +00:00
|
|
|
self::assertIsArray($dist);
|
2012-03-10 07:49:21 +00:00
|
|
|
$this->assertEquals('zip', $dist['type']);
|
2013-08-18 21:03:48 +00:00
|
|
|
$this->assertEquals('https://api.github.com/repos/composer/packagist/zipball/SOMESHA', $dist['url']);
|
|
|
|
$this->assertEquals($sha, $dist['reference']);
|
2012-03-10 07:49:21 +00:00
|
|
|
|
|
|
|
$source = $gitHubDriver->getSource($sha);
|
|
|
|
$this->assertEquals('git', $source['type']);
|
|
|
|
$this->assertEquals($repoUrl, $source['url']);
|
2013-08-18 21:03:48 +00:00
|
|
|
$this->assertEquals($sha, $source['reference']);
|
2012-03-10 07:49:21 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testPublicRepository2(): void
|
2012-08-10 09:43:37 +00:00
|
|
|
{
|
|
|
|
$repoUrl = 'http://github.com/composer/packagist';
|
|
|
|
$repoApiUrl = 'https://api.github.com/repos/composer/packagist';
|
2012-08-24 00:06:25 +00:00
|
|
|
$identifier = 'feature/3.2-foo';
|
2012-08-10 09:43:37 +00:00
|
|
|
$sha = 'SOMESHA';
|
|
|
|
|
2018-04-12 08:24:56 +00:00
|
|
|
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
2012-08-10 09:43:37 +00:00
|
|
|
$io->expects($this->any())
|
|
|
|
->method('isInteractive')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$httpDownloader = $this->getHttpDownloaderMock($io, $this->config);
|
|
|
|
$httpDownloader->expects(
|
|
|
|
[
|
|
|
|
['url' => $repoApiUrl, 'body' => '{"master_branch": "test_master", "owner": {"login": "composer"}, "name": "packagist"}'],
|
|
|
|
['url' => 'https://api.github.com/repos/composer/packagist/contents/composer.json?ref=feature%2F3.2-foo', 'body' => '{"encoding":"base64","content":"'.base64_encode('{"support": {"source": "'.$repoUrl.'" }}').'"}'],
|
|
|
|
['url' => 'https://api.github.com/repos/composer/packagist/commits/feature%2F3.2-foo', 'body' => '{"commit": {"committer":{ "date": "2012-09-10"}}}'],
|
|
|
|
['url' => 'https://api.github.com/repos/composer/packagist/contents/.github/FUNDING.yml', 'body' => '{"encoding": "base64", "content": "'.base64_encode("custom: https://example.com").'"}'],
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
2012-08-10 09:43:37 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$repoConfig = [
|
2012-08-31 06:12:20 +00:00
|
|
|
'url' => $repoUrl,
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2013-02-13 11:59:16 +00:00
|
|
|
$repoUrl = 'https://github.com/composer/packagist.git';
|
2012-08-31 06:12:20 +00:00
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $this->getProcessExecutorMock());
|
2012-08-10 09:43:37 +00:00
|
|
|
$gitHubDriver->initialize();
|
2022-08-17 12:20:07 +00:00
|
|
|
$this->setAttribute($gitHubDriver, 'tags', [$identifier => $sha]);
|
2012-08-10 09:43:37 +00:00
|
|
|
|
|
|
|
$this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
|
|
|
|
|
|
|
|
$dist = $gitHubDriver->getDist($sha);
|
2022-11-03 20:47:26 +00:00
|
|
|
self::assertIsArray($dist);
|
2012-08-10 09:43:37 +00:00
|
|
|
$this->assertEquals('zip', $dist['type']);
|
2013-08-18 21:03:48 +00:00
|
|
|
$this->assertEquals('https://api.github.com/repos/composer/packagist/zipball/SOMESHA', $dist['url']);
|
|
|
|
$this->assertEquals($sha, $dist['reference']);
|
2012-08-10 09:43:37 +00:00
|
|
|
|
|
|
|
$source = $gitHubDriver->getSource($sha);
|
|
|
|
$this->assertEquals('git', $source['type']);
|
|
|
|
$this->assertEquals($repoUrl, $source['url']);
|
2013-08-18 21:03:48 +00:00
|
|
|
$this->assertEquals($sha, $source['reference']);
|
2012-08-10 09:43:37 +00:00
|
|
|
|
2020-01-04 17:01:27 +00:00
|
|
|
$data = $gitHubDriver->getComposerInformation($identifier);
|
|
|
|
|
2022-02-22 21:10:52 +00:00
|
|
|
$this->assertIsArray($data);
|
2020-01-04 17:01:27 +00:00
|
|
|
$this->assertArrayNotHasKey('abandoned', $data);
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testPublicRepositoryArchived(): void
|
2020-01-04 17:01:27 +00:00
|
|
|
{
|
|
|
|
$repoUrl = 'http://github.com/composer/packagist';
|
|
|
|
$repoApiUrl = 'https://api.github.com/repos/composer/packagist';
|
|
|
|
$identifier = 'v0.0.0';
|
|
|
|
$sha = 'SOMESHA';
|
|
|
|
$composerJsonUrl = 'https://api.github.com/repos/composer/packagist/contents/composer.json?ref=' . $sha;
|
|
|
|
|
|
|
|
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
|
|
|
$io->expects($this->any())
|
|
|
|
->method('isInteractive')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$httpDownloader = $this->getHttpDownloaderMock($io, $this->config);
|
|
|
|
$httpDownloader->expects(
|
|
|
|
[
|
|
|
|
['url' => $repoApiUrl, 'body' => '{"master_branch": "test_master", "owner": {"login": "composer"}, "name": "packagist", "archived": true}'],
|
|
|
|
['url' => $composerJsonUrl, 'body' => '{"encoding": "base64", "content": "' . base64_encode('{"name": "composer/packagist"}') . '"}'],
|
|
|
|
['url' => 'https://api.github.com/repos/composer/packagist/commits/'.$sha, 'body' => '{"commit": {"committer":{ "date": "2012-09-10"}}}'],
|
|
|
|
['url' => 'https://api.github.com/repos/composer/packagist/contents/.github/FUNDING.yml', 'body' => '{"encoding": "base64", "content": "'.base64_encode("custom: https://example.com").'"}'],
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
2020-02-07 03:18:45 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$repoConfig = [
|
2020-01-04 17:01:27 +00:00
|
|
|
'url' => $repoUrl,
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2020-01-04 17:01:27 +00:00
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $this->getProcessExecutorMock());
|
2020-01-04 17:01:27 +00:00
|
|
|
$gitHubDriver->initialize();
|
2022-08-17 12:20:07 +00:00
|
|
|
$this->setAttribute($gitHubDriver, 'tags', [$identifier => $sha]);
|
2020-01-04 17:01:27 +00:00
|
|
|
|
|
|
|
$data = $gitHubDriver->getComposerInformation($sha);
|
|
|
|
|
2022-02-22 21:10:52 +00:00
|
|
|
$this->assertIsArray($data);
|
2020-01-04 17:01:27 +00:00
|
|
|
$this->assertTrue($data['abandoned']);
|
2012-08-10 09:43:37 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testPrivateRepositoryNoInteraction(): void
|
2012-03-10 07:49:21 +00:00
|
|
|
{
|
|
|
|
$repoUrl = 'http://github.com/composer/packagist';
|
2012-05-31 14:03:25 +00:00
|
|
|
$repoApiUrl = 'https://api.github.com/repos/composer/packagist';
|
2012-03-10 07:49:21 +00:00
|
|
|
$repoSshUrl = 'git@github.com:composer/packagist.git';
|
|
|
|
$identifier = 'v0.0.0';
|
|
|
|
$sha = 'SOMESHA';
|
|
|
|
|
2018-04-12 08:24:56 +00:00
|
|
|
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
2012-03-10 07:49:21 +00:00
|
|
|
$io->expects($this->any())
|
|
|
|
->method('isInteractive')
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$httpDownloader = $this->getHttpDownloaderMock($io, $this->config);
|
|
|
|
$httpDownloader->expects(
|
|
|
|
[
|
|
|
|
['url' => $repoApiUrl, 'status' => 404],
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
2012-03-10 07:49:21 +00:00
|
|
|
|
2012-03-15 17:32:31 +00:00
|
|
|
// clean local clone if present
|
|
|
|
$fs = new Filesystem();
|
2012-04-25 15:35:47 +00:00
|
|
|
$fs->removeDirectory(sys_get_temp_dir() . '/composer-test');
|
2022-01-21 15:15:28 +00:00
|
|
|
$this->config->merge(['config' => ['cache-vcs-dir' => sys_get_temp_dir() . '/composer-test/cache']]);
|
2012-04-25 15:35:47 +00:00
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$process = $this->getProcessExecutorMock();
|
2022-08-17 12:20:07 +00:00
|
|
|
$process->expects([
|
|
|
|
['cmd' => 'git config github.accesstoken', 'return' => 1],
|
2021-08-19 11:00:30 +00:00
|
|
|
'git clone --mirror -- '.ProcessExecutor::escape($repoSshUrl).' '.ProcessExecutor::escape($this->config->get('cache-vcs-dir').'/git-github.com-composer-packagist.git/'),
|
2022-08-17 12:20:07 +00:00
|
|
|
[
|
2021-08-19 11:00:30 +00:00
|
|
|
'cmd' => 'git show-ref --tags --dereference',
|
|
|
|
'stdout' => $sha.' refs/tags/'.$identifier,
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
[
|
2021-08-19 11:00:30 +00:00
|
|
|
'cmd' => 'git branch --no-color --no-abbrev -v',
|
|
|
|
'stdout' => ' test_master edf93f1fccaebd8764383dc12016d0a1a9672d89 Fix test & behavior',
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
[
|
2021-08-19 11:00:30 +00:00
|
|
|
'cmd' => 'git branch --no-color',
|
|
|
|
'stdout' => '* test_master',
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
], true);
|
2012-03-10 07:49:21 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$repoConfig = [
|
2012-08-31 06:12:20 +00:00
|
|
|
'url' => $repoUrl,
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2012-08-31 06:12:20 +00:00
|
|
|
|
2018-11-12 14:34:54 +00:00
|
|
|
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $process);
|
2012-03-10 07:49:21 +00:00
|
|
|
$gitHubDriver->initialize();
|
|
|
|
|
|
|
|
$this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
|
|
|
|
|
2014-02-24 18:51:03 +00:00
|
|
|
$dist = $gitHubDriver->getDist($sha);
|
2022-11-03 20:47:26 +00:00
|
|
|
self::assertIsArray($dist);
|
2014-02-24 18:51:03 +00:00
|
|
|
$this->assertEquals('zip', $dist['type']);
|
|
|
|
$this->assertEquals('https://api.github.com/repos/composer/packagist/zipball/SOMESHA', $dist['url']);
|
|
|
|
$this->assertEquals($sha, $dist['reference']);
|
2012-03-10 07:49:21 +00:00
|
|
|
|
|
|
|
$source = $gitHubDriver->getSource($identifier);
|
|
|
|
$this->assertEquals('git', $source['type']);
|
|
|
|
$this->assertEquals($repoSshUrl, $source['url']);
|
|
|
|
$this->assertEquals($identifier, $source['reference']);
|
|
|
|
|
|
|
|
$source = $gitHubDriver->getSource($sha);
|
|
|
|
$this->assertEquals('git', $source['type']);
|
|
|
|
$this->assertEquals($repoSshUrl, $source['url']);
|
|
|
|
$this->assertEquals($sha, $source['reference']);
|
|
|
|
}
|
|
|
|
|
2022-02-16 08:37:36 +00:00
|
|
|
/**
|
2022-08-16 09:08:03 +00:00
|
|
|
* @dataProvider invalidUrlProvider
|
2022-02-16 08:37:36 +00:00
|
|
|
*/
|
2022-08-17 12:20:07 +00:00
|
|
|
public function testInitializeInvalidRepoUrl(string $url): void
|
2022-02-16 08:37:36 +00:00
|
|
|
{
|
2022-02-16 12:35:30 +00:00
|
|
|
$this->expectException('\InvalidArgumentException');
|
2022-02-16 08:37:36 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$repoConfig = [
|
2022-08-16 09:08:03 +00:00
|
|
|
'url' => $url,
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2022-02-16 08:37:36 +00:00
|
|
|
|
|
|
|
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
|
|
|
$httpDownloader = $this->getMockBuilder('Composer\Util\HttpDownloader')
|
2022-08-17 12:20:07 +00:00
|
|
|
->setConstructorArgs([$io, $this->config])
|
2022-02-16 08:37:36 +00:00
|
|
|
->getMock();
|
|
|
|
|
2022-03-17 13:52:14 +00:00
|
|
|
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $this->getProcessExecutorMock());
|
2022-02-16 08:37:36 +00:00
|
|
|
$gitHubDriver->initialize();
|
|
|
|
}
|
|
|
|
|
2022-08-16 09:08:03 +00:00
|
|
|
/**
|
2022-08-16 09:25:15 +00:00
|
|
|
* @return list<array{string}>
|
2022-08-16 09:08:03 +00:00
|
|
|
*/
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function invalidUrlProvider()
|
2022-08-16 09:08:03 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
return [
|
|
|
|
['https://github.com/acme'],
|
|
|
|
['https://github.com/acme/repository/releases'],
|
|
|
|
['https://github.com/acme/repository/pulls'],
|
|
|
|
];
|
2022-08-16 09:08:03 +00:00
|
|
|
}
|
|
|
|
|
2022-02-16 08:37:36 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider supportsProvider
|
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testSupports(bool $expected, string $repoUrl): void
|
2022-02-16 08:37:36 +00:00
|
|
|
{
|
|
|
|
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
|
|
|
|
|
|
|
$this->assertSame($expected, GitHubDriver::supports($io, $this->config, $repoUrl));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return list<array{bool, string}>
|
|
|
|
*/
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function supportsProvider(): array
|
2022-02-16 08:37:36 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
return [
|
|
|
|
[false, 'https://github.com/acme'],
|
|
|
|
[true, 'https://github.com/acme/repository'],
|
|
|
|
[true, 'git@github.com:acme/repository.git'],
|
|
|
|
[false, 'https://github.com/acme/repository/releases'],
|
|
|
|
[false, 'https://github.com/acme/repository/pulls'],
|
|
|
|
];
|
2022-02-16 08:37:36 +00:00
|
|
|
}
|
|
|
|
|
2021-10-27 13:29:52 +00:00
|
|
|
/**
|
|
|
|
* @param string|object $object
|
|
|
|
* @param mixed $value
|
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
protected function setAttribute($object, string $attribute, $value): void
|
2012-03-10 07:49:21 +00:00
|
|
|
{
|
|
|
|
$attr = new \ReflectionProperty($object, $attribute);
|
|
|
|
$attr->setAccessible(true);
|
|
|
|
$attr->setValue($object, $value);
|
|
|
|
}
|
|
|
|
}
|