1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00
This commit is contained in:
Jordi Boggiano 2022-08-17 15:20:07 +03:00 committed by GitHub
parent 6e205a0c84
commit 131da999ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
357 changed files with 5943 additions and 9174 deletions

View file

@ -13,7 +13,6 @@
namespace Composer\Test\Repository\Vcs;
use Composer\Repository\Vcs\GitHubDriver;
use Composer\Test\Mock\ProcessExecutorMock;
use Composer\Test\TestCase;
use Composer\Util\Filesystem;
use Composer\Config;
@ -30,11 +29,11 @@ class GitHubDriverTest extends TestCase
{
$this->home = self::getUniqueTmpDirectory();
$this->config = new Config();
$this->config->merge(array(
'config' => array(
$this->config->merge([
'config' => [
'home' => $this->home,
),
));
],
]);
}
protected function tearDown(): void
@ -68,7 +67,7 @@ class GitHubDriverTest extends TestCase
);
$process = $this->getProcessExecutorMock();
$process->expects(array(), false, array('return' => 1));
$process->expects([], false, ['return' => 1]);
$io->expects($this->once())
->method('askAndHideAnswer')
@ -84,13 +83,13 @@ class GitHubDriverTest extends TestCase
$this->config->setConfigSource($configSource);
$this->config->setAuthConfigSource($authConfigSource);
$repoConfig = array(
$repoConfig = [
'url' => $repoUrl,
);
];
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $process);
$gitHubDriver->initialize();
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
$this->setAttribute($gitHubDriver, 'tags', [$identifier => $sha]);
$this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
@ -125,14 +124,14 @@ class GitHubDriverTest extends TestCase
true
);
$repoConfig = array(
$repoConfig = [
'url' => $repoUrl,
);
];
$repoUrl = 'https://github.com/composer/packagist.git';
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $this->getProcessExecutorMock());
$gitHubDriver->initialize();
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
$this->setAttribute($gitHubDriver, 'tags', [$identifier => $sha]);
$this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
@ -170,14 +169,14 @@ class GitHubDriverTest extends TestCase
true
);
$repoConfig = array(
$repoConfig = [
'url' => $repoUrl,
);
];
$repoUrl = 'https://github.com/composer/packagist.git';
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $this->getProcessExecutorMock());
$gitHubDriver->initialize();
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
$this->setAttribute($gitHubDriver, 'tags', [$identifier => $sha]);
$this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
@ -221,13 +220,13 @@ class GitHubDriverTest extends TestCase
true
);
$repoConfig = array(
$repoConfig = [
'url' => $repoUrl,
);
];
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $this->getProcessExecutorMock());
$gitHubDriver->initialize();
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
$this->setAttribute($gitHubDriver, 'tags', [$identifier => $sha]);
$data = $gitHubDriver->getComposerInformation($sha);
@ -262,26 +261,26 @@ class GitHubDriverTest extends TestCase
$this->config->merge(['config' => ['cache-vcs-dir' => sys_get_temp_dir() . '/composer-test/cache']]);
$process = $this->getProcessExecutorMock();
$process->expects(array(
array('cmd' => 'git config github.accesstoken', 'return' => 1),
$process->expects([
['cmd' => 'git config github.accesstoken', 'return' => 1],
'git clone --mirror -- '.ProcessExecutor::escape($repoSshUrl).' '.ProcessExecutor::escape($this->config->get('cache-vcs-dir').'/git-github.com-composer-packagist.git/'),
array(
[
'cmd' => 'git show-ref --tags --dereference',
'stdout' => $sha.' refs/tags/'.$identifier,
),
array(
],
[
'cmd' => 'git branch --no-color --no-abbrev -v',
'stdout' => ' test_master edf93f1fccaebd8764383dc12016d0a1a9672d89 Fix test & behavior',
),
array(
],
[
'cmd' => 'git branch --no-color',
'stdout' => '* test_master',
),
), true);
],
], true);
$repoConfig = array(
$repoConfig = [
'url' => $repoUrl,
);
];
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $process);
$gitHubDriver->initialize();
@ -306,20 +305,18 @@ class GitHubDriverTest extends TestCase
/**
* @dataProvider invalidUrlProvider
* @param string $url
* @return void
*/
public function testInitializeInvalidRepoUrl($url): void
public function testInitializeInvalidRepoUrl(string $url): void
{
$this->expectException('\InvalidArgumentException');
$repoConfig = array(
$repoConfig = [
'url' => $url,
);
];
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$httpDownloader = $this->getMockBuilder('Composer\Util\HttpDownloader')
->setConstructorArgs(array($io, $this->config))
->setConstructorArgs([$io, $this->config])
->getMock();
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $this->getProcessExecutorMock());
@ -331,17 +328,15 @@ class GitHubDriverTest extends TestCase
*/
public function invalidUrlProvider()
{
return array(
array('https://github.com/acme'),
array('https://github.com/acme/repository/releases'),
array('https://github.com/acme/repository/pulls'),
);
return [
['https://github.com/acme'],
['https://github.com/acme/repository/releases'],
['https://github.com/acme/repository/pulls'],
];
}
/**
* @dataProvider supportsProvider
* @param bool $expected
* @param string $repoUrl
*/
public function testSupports(bool $expected, string $repoUrl): void
{
@ -355,21 +350,18 @@ class GitHubDriverTest extends TestCase
*/
public function supportsProvider(): array
{
return array(
array(false, 'https://github.com/acme'),
array(true, 'https://github.com/acme/repository'),
array(true, 'git@github.com:acme/repository.git'),
array(false, 'https://github.com/acme/repository/releases'),
array(false, 'https://github.com/acme/repository/pulls'),
);
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'],
];
}
/**
* @param string|object $object
* @param string $attribute
* @param mixed $value
*
* @return void
*/
protected function setAttribute($object, string $attribute, $value): void
{