mirror of
https://github.com/composer/composer
synced 2025-05-09 08:32:56 +00:00
Fix CS (#11003)
This commit is contained in:
parent
6e205a0c84
commit
131da999ac
357 changed files with 5943 additions and 9174 deletions
|
@ -48,7 +48,6 @@ class GitDownloaderTest extends TestCase
|
|||
|
||||
/**
|
||||
* @param string|bool $version
|
||||
* @return void
|
||||
*/
|
||||
private function initGitVersion($version): void
|
||||
{
|
||||
|
@ -60,7 +59,6 @@ class GitDownloaderTest extends TestCase
|
|||
|
||||
/**
|
||||
* @param ?\Composer\Config $config
|
||||
* @return \Composer\Config
|
||||
*/
|
||||
protected function setupConfig($config = null): Config
|
||||
{
|
||||
|
@ -69,7 +67,7 @@ class GitDownloaderTest extends TestCase
|
|||
}
|
||||
if (!$config->has('home')) {
|
||||
$tmpDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'cmptest-'.md5(uniqid('', true));
|
||||
$config->merge(array('config' => array('home' => $tmpDir)));
|
||||
$config->merge(['config' => ['home' => $tmpDir]]);
|
||||
}
|
||||
|
||||
return $config;
|
||||
|
@ -80,9 +78,8 @@ class GitDownloaderTest extends TestCase
|
|||
* @param \Composer\Config $config
|
||||
* @param \Composer\Test\Mock\ProcessExecutorMock $executor
|
||||
* @param \Composer\Util\Filesystem $filesystem
|
||||
* @return GitDownloader
|
||||
*/
|
||||
protected function getDownloaderMock(\Composer\IO\IOInterface $io = null, Config $config = null, \Composer\Test\Mock\ProcessExecutorMock $executor = null, Filesystem $filesystem = null): GitDownloader
|
||||
protected function getDownloaderMock(?\Composer\IO\IOInterface $io = null, ?Config $config = null, ?\Composer\Test\Mock\ProcessExecutorMock $executor = null, ?Filesystem $filesystem = null): GitDownloader
|
||||
{
|
||||
$io = $io ?: $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
||||
$executor = $executor ?: $this->getProcessExecutorMock();
|
||||
|
@ -116,7 +113,7 @@ class GitDownloaderTest extends TestCase
|
|||
->will($this->returnValue('1234567890123456789012345678901234567890'));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getSourceUrls')
|
||||
->will($this->returnValue(array('https://example.com/composer/composer')));
|
||||
->will($this->returnValue(['https://example.com/composer/composer']));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getSourceUrl')
|
||||
->will($this->returnValue('https://example.com/composer/composer'));
|
||||
|
@ -125,11 +122,11 @@ class GitDownloaderTest extends TestCase
|
|||
->will($this->returnValue('dev-master'));
|
||||
|
||||
$process = $this->getProcessExecutorMock();
|
||||
$process->expects(array(
|
||||
$process->expects([
|
||||
$this->winCompat("git clone --no-checkout -- 'https://example.com/composer/composer' 'composerPath' && cd 'composerPath' && git remote add composer -- 'https://example.com/composer/composer' && git fetch composer && git remote set-url origin -- 'https://example.com/composer/composer' && git remote set-url composer -- 'https://example.com/composer/composer'"),
|
||||
$this->winCompat("git branch -r"),
|
||||
$this->winCompat("(git checkout 'master' -- || git checkout -B 'master' 'composer/master' --) && git reset --hard '1234567890123456789012345678901234567890' --"),
|
||||
), true);
|
||||
], true);
|
||||
|
||||
$downloader = $this->getDownloaderMock(null, null, $process);
|
||||
$downloader->download($packageMock, 'composerPath');
|
||||
|
@ -146,7 +143,7 @@ class GitDownloaderTest extends TestCase
|
|||
->will($this->returnValue('1234567890123456789012345678901234567890'));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getSourceUrls')
|
||||
->will($this->returnValue(array('https://example.com/composer/composer')));
|
||||
->will($this->returnValue(['https://example.com/composer/composer']));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getSourceUrl')
|
||||
->will($this->returnValue('https://example.com/composer/composer'));
|
||||
|
@ -164,16 +161,16 @@ class GitDownloaderTest extends TestCase
|
|||
$filesystem->removeDirectory($cachePath);
|
||||
|
||||
$process = $this->getProcessExecutorMock();
|
||||
$process->expects(array(
|
||||
array('cmd' => $this->winCompat(sprintf("git clone --mirror -- 'https://example.com/composer/composer' '%s'", $cachePath)), 'callback' => function () use ($cachePath): void {
|
||||
$process->expects([
|
||||
['cmd' => $this->winCompat(sprintf("git clone --mirror -- 'https://example.com/composer/composer' '%s'", $cachePath)), 'callback' => static function () use ($cachePath): void {
|
||||
@mkdir($cachePath, 0777, true);
|
||||
}),
|
||||
array('cmd' => 'git rev-parse --git-dir', 'stdout' => '.'),
|
||||
}],
|
||||
['cmd' => 'git rev-parse --git-dir', 'stdout' => '.'],
|
||||
$this->winCompat('git rev-parse --quiet --verify \'1234567890123456789012345678901234567890^{commit}\''),
|
||||
$this->winCompat(sprintf("git clone --no-checkout '%1\$s' 'composerPath' --dissociate --reference '%1\$s' && cd 'composerPath' && git remote set-url origin -- 'https://example.com/composer/composer' && git remote add composer -- 'https://example.com/composer/composer'", $cachePath)),
|
||||
'git branch -r',
|
||||
$this->winCompat("(git checkout 'master' -- || git checkout -B 'master' 'composer/master' --) && git reset --hard '1234567890123456789012345678901234567890' --"),
|
||||
), true);
|
||||
], true);
|
||||
|
||||
$downloader = $this->getDownloaderMock(null, $config, $process);
|
||||
$downloader->download($packageMock, 'composerPath');
|
||||
|
@ -191,7 +188,7 @@ class GitDownloaderTest extends TestCase
|
|||
->will($this->returnValue('ref'));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getSourceUrls')
|
||||
->will($this->returnValue(array('https://github.com/mirrors/composer', 'https://github.com/composer/composer')));
|
||||
->will($this->returnValue(['https://github.com/mirrors/composer', 'https://github.com/composer/composer']));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getSourceUrl')
|
||||
->will($this->returnValue('https://github.com/composer/composer'));
|
||||
|
@ -200,18 +197,18 @@ class GitDownloaderTest extends TestCase
|
|||
->will($this->returnValue('1.0.0'));
|
||||
|
||||
$process = $this->getProcessExecutorMock();
|
||||
$process->expects(array(
|
||||
array(
|
||||
$process->expects([
|
||||
[
|
||||
'cmd' => $this->winCompat("git clone --no-checkout -- 'https://github.com/mirrors/composer' 'composerPath' && cd 'composerPath' && git remote add composer -- 'https://github.com/mirrors/composer' && git fetch composer && git remote set-url origin -- 'https://github.com/mirrors/composer' && git remote set-url composer -- 'https://github.com/mirrors/composer'"),
|
||||
'return' => 1,
|
||||
'stderr' => 'Error1',
|
||||
),
|
||||
],
|
||||
$this->winCompat("git clone --no-checkout -- 'git@github.com:mirrors/composer' 'composerPath' && cd 'composerPath' && git remote add composer -- 'git@github.com:mirrors/composer' && git fetch composer && git remote set-url origin -- 'git@github.com:mirrors/composer' && git remote set-url composer -- 'git@github.com:mirrors/composer'"),
|
||||
$this->winCompat("git remote set-url origin -- 'https://github.com/composer/composer'"),
|
||||
$this->winCompat("git remote set-url --push origin -- 'git@github.com:composer/composer.git'"),
|
||||
'git branch -r',
|
||||
$this->winCompat("git checkout 'ref' -- && git reset --hard 'ref' --"),
|
||||
), true);
|
||||
], true);
|
||||
|
||||
$downloader = $this->getDownloaderMock(null, new Config(), $process);
|
||||
$downloader->download($packageMock, 'composerPath');
|
||||
|
@ -222,21 +219,19 @@ class GitDownloaderTest extends TestCase
|
|||
|
||||
public function pushUrlProvider(): array
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
// ssh proto should use git@ all along
|
||||
array(array('ssh'), 'git@github.com:composer/composer', 'git@github.com:composer/composer.git'),
|
||||
[['ssh'], 'git@github.com:composer/composer', 'git@github.com:composer/composer.git'],
|
||||
// auto-proto uses git@ by default for push url, but not fetch
|
||||
array(array('https', 'ssh', 'git'), 'https://github.com/composer/composer', 'git@github.com:composer/composer.git'),
|
||||
[['https', 'ssh', 'git'], 'https://github.com/composer/composer', 'git@github.com:composer/composer.git'],
|
||||
// if restricted to https then push url is not overwritten to git@
|
||||
array(array('https'), 'https://github.com/composer/composer', 'https://github.com/composer/composer.git'),
|
||||
);
|
||||
[['https'], 'https://github.com/composer/composer', 'https://github.com/composer/composer.git'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider pushUrlProvider
|
||||
* @param string[] $protocols
|
||||
* @param string $url
|
||||
* @param string $pushUrl
|
||||
*/
|
||||
public function testDownloadAndSetPushUrlUseCustomVariousProtocolsForGithub(array $protocols, string $url, string $pushUrl): void
|
||||
{
|
||||
|
@ -246,7 +241,7 @@ class GitDownloaderTest extends TestCase
|
|||
->will($this->returnValue('ref'));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getSourceUrls')
|
||||
->will($this->returnValue(array('https://github.com/composer/composer')));
|
||||
->will($this->returnValue(['https://github.com/composer/composer']));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getSourceUrl')
|
||||
->will($this->returnValue('https://github.com/composer/composer'));
|
||||
|
@ -255,15 +250,15 @@ class GitDownloaderTest extends TestCase
|
|||
->will($this->returnValue('1.0.0'));
|
||||
|
||||
$process = $this->getProcessExecutorMock();
|
||||
$process->expects(array(
|
||||
$process->expects([
|
||||
$this->winCompat("git clone --no-checkout -- '{$url}' 'composerPath' && cd 'composerPath' && git remote add composer -- '{$url}' && git fetch composer && git remote set-url origin -- '{$url}' && git remote set-url composer -- '{$url}'"),
|
||||
$this->winCompat("git remote set-url --push origin -- '{$pushUrl}'"),
|
||||
'git branch -r',
|
||||
$this->winCompat("git checkout 'ref' -- && git reset --hard 'ref' --"),
|
||||
), true);
|
||||
], true);
|
||||
|
||||
$config = new Config();
|
||||
$config->merge(array('config' => array('github-protocols' => $protocols)));
|
||||
$config->merge(['config' => ['github-protocols' => $protocols]]);
|
||||
|
||||
$downloader = $this->getDownloaderMock(null, $config, $process);
|
||||
$downloader->download($packageMock, 'composerPath');
|
||||
|
@ -280,7 +275,7 @@ class GitDownloaderTest extends TestCase
|
|||
->will($this->returnValue('ref'));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getSourceUrls')
|
||||
->will($this->returnValue(array('https://example.com/composer/composer')));
|
||||
->will($this->returnValue(['https://example.com/composer/composer']));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getSourceUrl')
|
||||
->will($this->returnValue('https://example.com/composer/composer'));
|
||||
|
@ -289,12 +284,12 @@ class GitDownloaderTest extends TestCase
|
|||
->will($this->returnValue('1.0.0'));
|
||||
|
||||
$process = $this->getProcessExecutorMock();
|
||||
$process->expects(array(
|
||||
array(
|
||||
$process->expects([
|
||||
[
|
||||
'cmd' => $this->winCompat("git clone --no-checkout -- 'https://example.com/composer/composer' 'composerPath' && cd 'composerPath' && git remote add composer -- 'https://example.com/composer/composer' && git fetch composer && git remote set-url origin -- 'https://example.com/composer/composer' && git remote set-url composer -- 'https://example.com/composer/composer'"),
|
||||
'return' => 1,
|
||||
),
|
||||
));
|
||||
],
|
||||
]);
|
||||
|
||||
// not using PHPUnit's expected exception because Prophecy exceptions extend from RuntimeException too so it is not safe
|
||||
try {
|
||||
|
@ -340,7 +335,7 @@ class GitDownloaderTest extends TestCase
|
|||
->will($this->returnValue('ref'));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getSourceUrls')
|
||||
->will($this->returnValue(array('https://github.com/composer/composer')));
|
||||
->will($this->returnValue(['https://github.com/composer/composer']));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getVersion')
|
||||
->will($this->returnValue('1.0.0.0'));
|
||||
|
@ -349,7 +344,7 @@ class GitDownloaderTest extends TestCase
|
|||
->will($this->returnValue('1.0.0'));
|
||||
|
||||
$process = $this->getProcessExecutorMock();
|
||||
$process->expects(array(
|
||||
$process->expects([
|
||||
$this->winCompat('git show-ref --head -d'),
|
||||
$this->winCompat('git status --porcelain --untracked-files=no'),
|
||||
$this->winCompat('git remote -v'),
|
||||
|
@ -357,7 +352,7 @@ class GitDownloaderTest extends TestCase
|
|||
$this->winCompat('git branch -r'),
|
||||
$this->winCompat("git checkout 'ref' -- && git reset --hard 'ref' --"),
|
||||
$this->winCompat('git remote -v'),
|
||||
), true);
|
||||
], true);
|
||||
|
||||
$this->fs->ensureDirectoryExists($this->workingDir.'/.git');
|
||||
$downloader = $this->getDownloaderMock(null, new Config(), $process);
|
||||
|
@ -377,7 +372,7 @@ class GitDownloaderTest extends TestCase
|
|||
->will($this->returnValue('ref'));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getSourceUrls')
|
||||
->will($this->returnValue(array('https://github.com/composer/composer')));
|
||||
->will($this->returnValue(['https://github.com/composer/composer']));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getSourceUrl')
|
||||
->will($this->returnValue('https://github.com/composer/composer'));
|
||||
|
@ -389,24 +384,24 @@ class GitDownloaderTest extends TestCase
|
|||
->will($this->returnValue('1.0.0'));
|
||||
|
||||
$process = $this->getProcessExecutorMock();
|
||||
$process->expects(array(
|
||||
$process->expects([
|
||||
$this->winCompat("git show-ref --head -d"),
|
||||
$this->winCompat("git status --porcelain --untracked-files=no"),
|
||||
$this->winCompat("git remote -v"),
|
||||
$this->winCompat($expectedGitUpdateCommand),
|
||||
'git branch -r',
|
||||
$this->winCompat("git checkout 'ref' -- && git reset --hard 'ref' --"),
|
||||
array(
|
||||
[
|
||||
'cmd' => $this->winCompat("git remote -v"),
|
||||
'stdout' => 'origin https://github.com/old/url (fetch)
|
||||
origin https://github.com/old/url (push)
|
||||
composer https://github.com/old/url (fetch)
|
||||
composer https://github.com/old/url (push)
|
||||
',
|
||||
),
|
||||
],
|
||||
$this->winCompat("git remote set-url origin -- 'https://github.com/composer/composer'"),
|
||||
$this->winCompat("git remote set-url --push origin -- 'git@github.com:composer/composer.git'"),
|
||||
), true);
|
||||
], true);
|
||||
|
||||
$this->fs->ensureDirectoryExists($this->workingDir.'/.git');
|
||||
$downloader = $this->getDownloaderMock(null, new Config(), $process);
|
||||
|
@ -430,26 +425,26 @@ composer https://github.com/old/url (push)
|
|||
->will($this->returnValue('ref'));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getSourceUrls')
|
||||
->will($this->returnValue(array('https://github.com/composer/composer')));
|
||||
->will($this->returnValue(['https://github.com/composer/composer']));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getVersion')
|
||||
->will($this->returnValue('1.0.0.0'));
|
||||
|
||||
$process = $this->getProcessExecutorMock();
|
||||
$process->expects(array(
|
||||
$process->expects([
|
||||
$this->winCompat('git show-ref --head -d'),
|
||||
$this->winCompat('git status --porcelain --untracked-files=no'),
|
||||
$this->winCompat('git remote -v'),
|
||||
array(
|
||||
[
|
||||
'cmd' => $expectedGitUpdateCommand,
|
||||
'return' => 1,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'cmd' => $expectedGitUpdateCommand2,
|
||||
'return' => 1,
|
||||
),
|
||||
],
|
||||
$this->winCompat('git --version'),
|
||||
), true);
|
||||
], true);
|
||||
|
||||
$this->fs->ensureDirectoryExists($this->workingDir.'/.git');
|
||||
|
||||
|
@ -484,30 +479,30 @@ composer https://github.com/old/url (push)
|
|||
->will($this->returnValue('1.0.0.0'));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getSourceUrls')
|
||||
->will($this->returnValue(array(Platform::isWindows() ? 'C:\\' : '/', 'https://github.com/composer/composer')));
|
||||
->will($this->returnValue([Platform::isWindows() ? 'C:\\' : '/', 'https://github.com/composer/composer']));
|
||||
$packageMock->expects($this->any())
|
||||
->method('getPrettyVersion')
|
||||
->will($this->returnValue('1.0.0'));
|
||||
|
||||
$process = $this->getProcessExecutorMock();
|
||||
$process->expects(array(
|
||||
$process->expects([
|
||||
$this->winCompat('git show-ref --head -d'),
|
||||
$this->winCompat('git status --porcelain --untracked-files=no'),
|
||||
$this->winCompat('git remote -v'),
|
||||
array(
|
||||
[
|
||||
'cmd' => $expectedFirstGitUpdateCommand,
|
||||
'return' => 1,
|
||||
),
|
||||
],
|
||||
$this->winCompat('git --version'),
|
||||
$this->winCompat('git remote -v'),
|
||||
array(
|
||||
[
|
||||
'cmd' => $expectedSecondGitUpdateCommand,
|
||||
'return' => 0,
|
||||
),
|
||||
],
|
||||
$this->winCompat('git branch -r'),
|
||||
$this->winCompat("git checkout 'ref' -- && git reset --hard 'ref' --"),
|
||||
$this->winCompat('git remote -v'),
|
||||
), true);
|
||||
], true);
|
||||
|
||||
$this->fs->ensureDirectoryExists($this->workingDir.'/.git');
|
||||
$downloader = $this->getDownloaderMock(null, new Config(), $process);
|
||||
|
@ -531,7 +526,7 @@ composer https://github.com/old/url (push)
|
|||
->will($this->returnValue('ref'));
|
||||
$oldPackage->expects($this->any())
|
||||
->method('getSourceUrls')
|
||||
->will($this->returnValue(array('/foo/bar', 'https://github.com/composer/composer')));
|
||||
->will($this->returnValue(['/foo/bar', 'https://github.com/composer/composer']));
|
||||
|
||||
$newPackage = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock();
|
||||
$newPackage->expects($this->any())
|
||||
|
@ -539,7 +534,7 @@ composer https://github.com/old/url (push)
|
|||
->will($this->returnValue('ref'));
|
||||
$newPackage->expects($this->any())
|
||||
->method('getSourceUrls')
|
||||
->will($this->returnValue(array('https://github.com/composer/composer')));
|
||||
->will($this->returnValue(['https://github.com/composer/composer']));
|
||||
$newPackage->expects($this->any())
|
||||
->method('getVersion')
|
||||
->will($this->returnValue('1.0.0.0'));
|
||||
|
@ -578,7 +573,7 @@ composer https://github.com/old/url (push)
|
|||
->will($this->returnValue('ref'));
|
||||
$oldPackage->expects($this->any())
|
||||
->method('getSourceUrls')
|
||||
->will($this->returnValue(array('/foo/bar', 'https://github.com/composer/composer')));
|
||||
->will($this->returnValue(['/foo/bar', 'https://github.com/composer/composer']));
|
||||
|
||||
$newPackage = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock();
|
||||
$newPackage->expects($this->any())
|
||||
|
@ -586,7 +581,7 @@ composer https://github.com/old/url (push)
|
|||
->will($this->returnValue('ref'));
|
||||
$newPackage->expects($this->any())
|
||||
->method('getSourceUrls')
|
||||
->will($this->returnValue(array('https://github.com/composer/composer')));
|
||||
->will($this->returnValue(['https://github.com/composer/composer']));
|
||||
$newPackage->expects($this->any())
|
||||
->method('getVersion')
|
||||
->will($this->returnValue('dev-ref2'));
|
||||
|
@ -617,10 +612,10 @@ composer https://github.com/old/url (push)
|
|||
|
||||
$packageMock = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock();
|
||||
$process = $this->getProcessExecutorMock();
|
||||
$process->expects(array(
|
||||
$process->expects([
|
||||
'git show-ref --head -d',
|
||||
$expectedGitResetCommand,
|
||||
), true);
|
||||
], true);
|
||||
|
||||
$this->fs->ensureDirectoryExists($this->workingDir.'/.git');
|
||||
|
||||
|
@ -643,10 +638,6 @@ composer https://github.com/old/url (push)
|
|||
$this->assertEquals('source', $downloader->getInstallationSource());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $cmd
|
||||
* @return string
|
||||
*/
|
||||
private function winCompat(string $cmd): string
|
||||
{
|
||||
if (Platform::isWindows()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue