2012-03-10 07:49:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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\Downloader\TransportException;
|
|
|
|
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;
|
2018-10-31 11:44:54 +00:00
|
|
|
use Composer\Util\Http\Response;
|
2012-04-25 15:35:47 +00:00
|
|
|
use Composer\Config;
|
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
|
|
|
{
|
2016-01-21 12:01:55 +00:00
|
|
|
private $home;
|
2012-05-13 19:40:42 +00:00
|
|
|
private $config;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2016-01-21 12:01:55 +00:00
|
|
|
$this->home = $this->getUniqueTmpDirectory();
|
2012-05-13 19:40:42 +00:00
|
|
|
$this->config = new Config();
|
|
|
|
$this->config->merge(array(
|
|
|
|
'config' => array(
|
2016-01-21 12:01:55 +00:00
|
|
|
'home' => $this->home,
|
2012-05-13 19:40:42 +00:00
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2012-11-10 20:54:23 +00:00
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
$fs = new Filesystem;
|
2016-01-21 12:01:55 +00:00
|
|
|
$fs->removeDirectory($this->home);
|
2012-11-10 20:54:23 +00:00
|
|
|
}
|
|
|
|
|
2012-03-10 07:49:21 +00:00
|
|
|
public function testPrivateRepository()
|
|
|
|
{
|
|
|
|
$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));
|
|
|
|
|
2018-10-31 11:44:54 +00:00
|
|
|
$httpDownloader = $this->getMockBuilder('Composer\Util\HttpDownloader')
|
|
|
|
->setConstructorArgs(array($io, $this->config))
|
2012-03-10 07:49:21 +00:00
|
|
|
->getMock();
|
|
|
|
|
2018-04-12 08:24:56 +00:00
|
|
|
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
|
2012-06-27 16:28:49 +00:00
|
|
|
$process->expects($this->any())
|
|
|
|
->method('execute')
|
|
|
|
->will($this->returnValue(1));
|
|
|
|
|
2018-10-31 11:44:54 +00:00
|
|
|
$httpDownloader->expects($this->at(0))
|
|
|
|
->method('get')
|
|
|
|
->with($this->equalTo($repoApiUrl))
|
2012-03-10 07:49:21 +00:00
|
|
|
->will($this->throwException(new TransportException('HTTP/1.1 404 Not Found', 404)));
|
|
|
|
|
|
|
|
$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-10-31 11:44:54 +00:00
|
|
|
$httpDownloader->expects($this->at(1))
|
|
|
|
->method('get')
|
|
|
|
->with($this->equalTo($url = 'https://api.github.com/'))
|
|
|
|
->will($this->returnValue(new Response(array('url' => $url), 200, array(), '{}')));
|
2014-02-26 16:38:58 +00:00
|
|
|
|
2018-10-31 11:44:54 +00:00
|
|
|
$httpDownloader->expects($this->at(2))
|
|
|
|
->method('get')
|
|
|
|
->with($this->equalTo($url = $repoApiUrl))
|
|
|
|
->will($this->returnValue(new Response(array('url' => $url), 200, array(), '{"master_branch": "test_master", "private": true, "owner": {"login": "composer"}, "name": "packagist"}')));
|
2012-10-18 16:43:31 +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
|
|
|
|
2012-08-31 06:12:20 +00:00
|
|
|
$repoConfig = array(
|
|
|
|
'url' => $repoUrl,
|
|
|
|
);
|
|
|
|
|
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->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
|
|
|
|
|
|
|
|
$this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
|
|
|
|
|
|
|
|
$dist = $gitHubDriver->getDist($sha);
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
|
|
public function testPublicRepository()
|
|
|
|
{
|
|
|
|
$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));
|
|
|
|
|
2018-10-31 11:44:54 +00:00
|
|
|
$httpDownloader = $this->getMockBuilder('Composer\Util\HttpDownloader')
|
|
|
|
->setConstructorArgs(array($io, $this->config))
|
2012-03-10 07:49:21 +00:00
|
|
|
->getMock();
|
|
|
|
|
2018-10-31 11:44:54 +00:00
|
|
|
$httpDownloader->expects($this->at(0))
|
|
|
|
->method('get')
|
|
|
|
->with($this->equalTo($repoApiUrl))
|
|
|
|
->will($this->returnValue(new Response(array('url' => $repoApiUrl), 200, array(), '{"master_branch": "test_master", "owner": {"login": "composer"}, "name": "packagist"}')));
|
2012-03-10 07:49:21 +00:00
|
|
|
|
2012-08-31 06:12:20 +00:00
|
|
|
$repoConfig = array(
|
|
|
|
'url' => $repoUrl,
|
|
|
|
);
|
2013-02-13 11:59:16 +00:00
|
|
|
$repoUrl = 'https://github.com/composer/packagist.git';
|
2012-08-31 06:12:20 +00:00
|
|
|
|
2018-11-12 14:34:54 +00:00
|
|
|
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $process);
|
2012-03-10 07:49:21 +00:00
|
|
|
$gitHubDriver->initialize();
|
|
|
|
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
|
|
|
|
|
|
|
|
$this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
|
|
|
|
|
|
|
|
$dist = $gitHubDriver->getDist($sha);
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
2012-08-10 09:43:37 +00:00
|
|
|
public function testPublicRepository2()
|
|
|
|
{
|
|
|
|
$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));
|
|
|
|
|
2018-10-31 11:44:54 +00:00
|
|
|
$httpDownloader = $this->getMockBuilder('Composer\Util\HttpDownloader')
|
|
|
|
->setConstructorArgs(array($io, $this->config))
|
2012-08-10 09:43:37 +00:00
|
|
|
->getMock();
|
|
|
|
|
2018-10-31 11:44:54 +00:00
|
|
|
$httpDownloader->expects($this->at(0))
|
|
|
|
->method('get')
|
|
|
|
->with($this->equalTo($url = $repoApiUrl))
|
|
|
|
->will($this->returnValue(new Response(array('url' => $url), 200, array(), '{"master_branch": "test_master", "owner": {"login": "composer"}, "name": "packagist"}')));
|
2012-08-10 09:43:37 +00:00
|
|
|
|
2018-10-31 11:44:54 +00:00
|
|
|
$httpDownloader->expects($this->at(1))
|
|
|
|
->method('get')
|
|
|
|
->with($this->equalTo($url = 'https://api.github.com/repos/composer/packagist/contents/composer.json?ref=feature%2F3.2-foo'))
|
|
|
|
->will($this->returnValue(new Response(array('url' => $url), 200, array(), '{"encoding":"base64","content":"'.base64_encode('{"support": {"source": "'.$repoUrl.'" }}').'"}')));
|
2012-08-10 09:43:37 +00:00
|
|
|
|
2018-10-31 11:44:54 +00:00
|
|
|
$httpDownloader->expects($this->at(2))
|
|
|
|
->method('get')
|
|
|
|
->with($this->equalTo($url = 'https://api.github.com/repos/composer/packagist/commits/feature%2F3.2-foo'))
|
|
|
|
->will($this->returnValue(new Response(array('url' => $url), 200, array(), '{"commit": {"committer":{ "date": "2012-09-10"}}}')));
|
2012-08-10 09:43:37 +00:00
|
|
|
|
2012-08-31 06:12:20 +00:00
|
|
|
$repoConfig = array(
|
|
|
|
'url' => $repoUrl,
|
|
|
|
);
|
2013-02-13 11:59:16 +00:00
|
|
|
$repoUrl = 'https://github.com/composer/packagist.git';
|
2012-08-31 06:12:20 +00:00
|
|
|
|
2018-11-12 14:34:54 +00:00
|
|
|
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config,$httpDownloader, $process);
|
2012-08-10 09:43:37 +00:00
|
|
|
$gitHubDriver->initialize();
|
|
|
|
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
|
|
|
|
|
|
|
|
$this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
|
|
|
|
|
|
|
|
$dist = $gitHubDriver->getDist($sha);
|
|
|
|
$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
|
|
|
|
|
|
|
$gitHubDriver->getComposerInformation($identifier);
|
|
|
|
}
|
|
|
|
|
2012-03-10 07:49:21 +00:00
|
|
|
public function testPrivateRepositoryNoInteraction()
|
|
|
|
{
|
|
|
|
$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';
|
|
|
|
|
|
|
|
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
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));
|
|
|
|
|
2018-10-31 11:44:54 +00:00
|
|
|
$httpDownloader = $this->getMockBuilder('Composer\Util\HttpDownloader')
|
|
|
|
->setConstructorArgs(array($io, $this->config))
|
2012-03-10 07:49:21 +00:00
|
|
|
->getMock();
|
|
|
|
|
2018-10-31 11:44:54 +00:00
|
|
|
$httpDownloader->expects($this->at(0))
|
|
|
|
->method('get')
|
|
|
|
->with($this->equalTo($repoApiUrl))
|
2012-03-10 07:49:21 +00:00
|
|
|
->will($this->throwException(new TransportException('HTTP/1.1 404 Not Found', 404)));
|
|
|
|
|
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');
|
|
|
|
|
2012-03-10 07:49:21 +00:00
|
|
|
$process->expects($this->at(0))
|
2012-10-22 15:11:34 +00:00
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo('git config github.accesstoken'))
|
|
|
|
->will($this->returnValue(1));
|
|
|
|
|
|
|
|
$process->expects($this->at(1))
|
2012-03-10 07:49:21 +00:00
|
|
|
->method('execute')
|
2012-04-02 22:38:38 +00:00
|
|
|
->with($this->stringContains($repoSshUrl))
|
|
|
|
->will($this->returnValue(0));
|
2012-03-10 07:49:21 +00:00
|
|
|
|
2012-10-22 15:11:34 +00:00
|
|
|
$process->expects($this->at(2))
|
2012-03-10 07:49:21 +00:00
|
|
|
->method('execute')
|
2013-08-18 23:21:17 +00:00
|
|
|
->with($this->stringContains('git show-ref --tags'));
|
2012-03-10 07:49:21 +00:00
|
|
|
|
2012-10-22 15:11:34 +00:00
|
|
|
$process->expects($this->at(3))
|
2012-03-10 07:49:21 +00:00
|
|
|
->method('splitLines')
|
2013-08-18 23:21:17 +00:00
|
|
|
->will($this->returnValue(array($sha.' refs/tags/'.$identifier)));
|
2012-03-10 07:49:21 +00:00
|
|
|
|
2012-10-22 15:11:34 +00:00
|
|
|
$process->expects($this->at(4))
|
2012-03-10 07:49:21 +00:00
|
|
|
->method('execute')
|
2012-04-02 22:38:38 +00:00
|
|
|
->with($this->stringContains('git branch --no-color --no-abbrev -v'));
|
2012-03-10 07:49:21 +00:00
|
|
|
|
2012-10-22 15:11:34 +00:00
|
|
|
$process->expects($this->at(5))
|
2012-03-10 07:49:21 +00:00
|
|
|
->method('splitLines')
|
2012-04-02 22:38:38 +00:00
|
|
|
->will($this->returnValue(array(' test_master edf93f1fccaebd8764383dc12016d0a1a9672d89 Fix test & behavior')));
|
2012-03-10 07:49:21 +00:00
|
|
|
|
2012-10-22 15:11:34 +00:00
|
|
|
$process->expects($this->at(6))
|
2012-03-10 07:49:21 +00:00
|
|
|
->method('execute')
|
2012-04-02 22:38:38 +00:00
|
|
|
->with($this->stringContains('git branch --no-color'));
|
2012-03-10 07:49:21 +00:00
|
|
|
|
2012-10-22 15:11:34 +00:00
|
|
|
$process->expects($this->at(7))
|
2012-03-10 07:49:21 +00:00
|
|
|
->method('splitLines')
|
2012-04-02 22:38:38 +00:00
|
|
|
->will($this->returnValue(array('* test_master')));
|
2012-03-10 07:49:21 +00:00
|
|
|
|
2012-08-31 06:12:20 +00:00
|
|
|
$repoConfig = array(
|
|
|
|
'url' => $repoUrl,
|
|
|
|
);
|
|
|
|
|
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);
|
|
|
|
$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']);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function setAttribute($object, $attribute, $value)
|
|
|
|
{
|
|
|
|
$attr = new \ReflectionProperty($object, $attribute);
|
|
|
|
$attr->setAccessible(true);
|
|
|
|
$attr->setValue($object, $value);
|
|
|
|
}
|
|
|
|
}
|