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;
|
2012-03-15 17:32:31 +00:00
|
|
|
use Composer\Util\Filesystem;
|
2012-04-25 15:35:47 +00:00
|
|
|
use Composer\Config;
|
2012-03-10 07:49:21 +00:00
|
|
|
|
|
|
|
class GitHubDriverTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testPrivateRepository()
|
|
|
|
{
|
2012-03-18 12:05:20 +00:00
|
|
|
$scheme = extension_loaded('openssl') ? 'https' : 'http';
|
|
|
|
|
2012-03-10 07:49:21 +00:00
|
|
|
$repoUrl = 'http://github.com/composer/packagist';
|
2012-03-18 12:05:20 +00:00
|
|
|
$repoApiUrl = $scheme.'://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';
|
|
|
|
|
|
|
|
$io = $this->getMock('Composer\IO\IOInterface');
|
|
|
|
$io->expects($this->any())
|
|
|
|
->method('isInteractive')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$remoteFilesystem = $this->getMockBuilder('Composer\Util\RemoteFilesystem')
|
|
|
|
->setConstructorArgs(array($io))
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$remoteFilesystem->expects($this->at(0))
|
|
|
|
->method('getContents')
|
2012-05-06 15:18:26 +00:00
|
|
|
->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
|
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('ask')
|
|
|
|
->with($this->equalTo('Username: '))
|
|
|
|
->will($this->returnValue('someuser'));
|
|
|
|
|
|
|
|
$io->expects($this->once())
|
|
|
|
->method('askAndHideAnswer')
|
|
|
|
->with($this->equalTo('Password: '))
|
|
|
|
->will($this->returnValue('somepassword'));
|
|
|
|
|
|
|
|
$io->expects($this->once())
|
|
|
|
->method('setAuthorization')
|
2012-05-06 15:18:26 +00:00
|
|
|
->with($this->equalTo('github.com'), 'someuser', 'somepassword');
|
2012-03-10 07:49:21 +00:00
|
|
|
|
|
|
|
$remoteFilesystem->expects($this->at(1))
|
|
|
|
->method('getContents')
|
2012-05-06 15:18:26 +00:00
|
|
|
->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
|
2012-03-10 07:49:21 +00:00
|
|
|
->will($this->returnValue('{"master_branch": "test_master"}'));
|
|
|
|
|
2012-04-25 15:35:47 +00:00
|
|
|
$gitHubDriver = new GitHubDriver($repoUrl, $io, new Config(), null, $remoteFilesystem);
|
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($identifier);
|
|
|
|
$this->assertEquals('zip', $dist['type']);
|
2012-03-18 12:05:20 +00:00
|
|
|
$this->assertEquals($scheme.'://github.com/composer/packagist/zipball/v0.0.0', $dist['url']);
|
2012-03-10 07:49:21 +00:00
|
|
|
$this->assertEquals('v0.0.0', $dist['reference']);
|
|
|
|
|
|
|
|
$source = $gitHubDriver->getSource($identifier);
|
|
|
|
$this->assertEquals('git', $source['type']);
|
|
|
|
$this->assertEquals($repoSshUrl, $source['url']);
|
|
|
|
$this->assertEquals('v0.0.0', $source['reference']);
|
|
|
|
|
|
|
|
$dist = $gitHubDriver->getDist($sha);
|
|
|
|
$this->assertEquals('zip', $dist['type']);
|
2012-03-18 12:05:20 +00:00
|
|
|
$this->assertEquals($scheme.'://github.com/composer/packagist/zipball/v0.0.0', $dist['url']);
|
2012-03-10 07:49:21 +00:00
|
|
|
$this->assertEquals('v0.0.0', $dist['reference']);
|
|
|
|
|
|
|
|
$source = $gitHubDriver->getSource($sha);
|
|
|
|
$this->assertEquals('git', $source['type']);
|
|
|
|
$this->assertEquals($repoSshUrl, $source['url']);
|
|
|
|
$this->assertEquals('v0.0.0', $source['reference']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPublicRepository()
|
|
|
|
{
|
2012-03-18 12:05:20 +00:00
|
|
|
$scheme = extension_loaded('openssl') ? 'https' : 'http';
|
|
|
|
|
2012-03-10 07:49:21 +00:00
|
|
|
$repoUrl = 'http://github.com/composer/packagist';
|
2012-03-18 12:05:20 +00:00
|
|
|
$repoApiUrl = $scheme.'://api.github.com/repos/composer/packagist';
|
2012-03-10 07:49:21 +00:00
|
|
|
$identifier = 'v0.0.0';
|
|
|
|
$sha = 'SOMESHA';
|
|
|
|
|
|
|
|
$io = $this->getMock('Composer\IO\IOInterface');
|
|
|
|
$io->expects($this->any())
|
|
|
|
->method('isInteractive')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$remoteFilesystem = $this->getMockBuilder('Composer\Util\RemoteFilesystem')
|
|
|
|
->setConstructorArgs(array($io))
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$remoteFilesystem->expects($this->at(0))
|
|
|
|
->method('getContents')
|
2012-05-06 15:18:26 +00:00
|
|
|
->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
|
2012-03-10 07:49:21 +00:00
|
|
|
->will($this->returnValue('{"master_branch": "test_master"}'));
|
|
|
|
|
2012-04-25 15:35:47 +00:00
|
|
|
$gitHubDriver = new GitHubDriver($repoUrl, $io, new Config(), null, $remoteFilesystem);
|
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($identifier);
|
|
|
|
$this->assertEquals('zip', $dist['type']);
|
2012-03-18 12:05:20 +00:00
|
|
|
$this->assertEquals($scheme.'://github.com/composer/packagist/zipball/v0.0.0', $dist['url']);
|
2012-03-10 07:49:21 +00:00
|
|
|
$this->assertEquals($identifier, $dist['reference']);
|
|
|
|
|
|
|
|
$source = $gitHubDriver->getSource($identifier);
|
|
|
|
$this->assertEquals('git', $source['type']);
|
|
|
|
$this->assertEquals($repoUrl, $source['url']);
|
|
|
|
$this->assertEquals($identifier, $source['reference']);
|
|
|
|
|
|
|
|
$dist = $gitHubDriver->getDist($sha);
|
|
|
|
$this->assertEquals('zip', $dist['type']);
|
2012-03-18 12:05:20 +00:00
|
|
|
$this->assertEquals($scheme.'://github.com/composer/packagist/zipball/v0.0.0', $dist['url']);
|
2012-03-10 07:49:21 +00:00
|
|
|
$this->assertEquals($identifier, $dist['reference']);
|
|
|
|
|
|
|
|
$source = $gitHubDriver->getSource($sha);
|
|
|
|
$this->assertEquals('git', $source['type']);
|
|
|
|
$this->assertEquals($repoUrl, $source['url']);
|
|
|
|
$this->assertEquals($identifier, $source['reference']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPrivateRepositoryNoInteraction()
|
|
|
|
{
|
2012-03-18 12:05:20 +00:00
|
|
|
$scheme = extension_loaded('openssl') ? 'https' : 'http';
|
|
|
|
|
2012-03-10 07:49:21 +00:00
|
|
|
$repoUrl = 'http://github.com/composer/packagist';
|
2012-03-18 12:05:20 +00:00
|
|
|
$repoApiUrl = $scheme.'://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();
|
|
|
|
|
|
|
|
$io = $this->getMock('Composer\IO\IOInterface');
|
|
|
|
$io->expects($this->any())
|
|
|
|
->method('isInteractive')
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
|
|
|
$remoteFilesystem = $this->getMockBuilder('Composer\Util\RemoteFilesystem')
|
|
|
|
->setConstructorArgs(array($io))
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$remoteFilesystem->expects($this->at(0))
|
|
|
|
->method('getContents')
|
2012-05-06 15:18:26 +00:00
|
|
|
->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
|
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');
|
|
|
|
|
|
|
|
$config = new Config();
|
|
|
|
$config->merge(array(
|
|
|
|
'config' => array(
|
|
|
|
'home' => sys_get_temp_dir() . '/composer-test',
|
|
|
|
),
|
|
|
|
));
|
2012-03-15 17:32:31 +00:00
|
|
|
|
2012-03-10 07:49:21 +00:00
|
|
|
$process->expects($this->at(0))
|
|
|
|
->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
|
|
|
|
|
|
|
$process->expects($this->at(1))
|
|
|
|
->method('execute')
|
|
|
|
->with($this->stringContains('git tag'));
|
|
|
|
|
|
|
|
$process->expects($this->at(2))
|
|
|
|
->method('splitLines')
|
|
|
|
->will($this->returnValue(array($identifier)));
|
|
|
|
|
|
|
|
$process->expects($this->at(3))
|
|
|
|
->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
|
|
|
|
|
|
|
$process->expects($this->at(4))
|
|
|
|
->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
|
|
|
|
|
|
|
$process->expects($this->at(5))
|
|
|
|
->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
|
|
|
|
|
|
|
$process->expects($this->at(6))
|
|
|
|
->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-04-25 15:35:47 +00:00
|
|
|
$gitHubDriver = new GitHubDriver($repoUrl, $io, $config, $process, $remoteFilesystem);
|
2012-03-10 07:49:21 +00:00
|
|
|
$gitHubDriver->initialize();
|
|
|
|
|
|
|
|
$this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
|
|
|
|
|
|
|
|
// Dist is not available for GitDriver
|
|
|
|
$dist = $gitHubDriver->getDist($identifier);
|
|
|
|
$this->assertNull($dist);
|
|
|
|
|
|
|
|
$source = $gitHubDriver->getSource($identifier);
|
|
|
|
$this->assertEquals('git', $source['type']);
|
|
|
|
$this->assertEquals($repoSshUrl, $source['url']);
|
|
|
|
$this->assertEquals($identifier, $source['reference']);
|
|
|
|
|
|
|
|
// Dist is not available for GitDriver
|
|
|
|
$dist = $gitHubDriver->getDist($sha);
|
|
|
|
$this->assertNull($dist);
|
|
|
|
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
}
|