diff --git a/src/Composer/Config/JsonConfigSource.php b/src/Composer/Config/JsonConfigSource.php index 384e153c8..4e116cc60 100644 --- a/src/Composer/Config/JsonConfigSource.php +++ b/src/Composer/Config/JsonConfigSource.php @@ -30,14 +30,14 @@ class JsonConfigSource implements ConfigSourceInterface public function addRepository($name, $config) { - return $this->manipulateJson('addRepository', $name, $config, function (&$config, $repo, $repoConfig) { + $this->manipulateJson('addRepository', $name, $config, function (&$config, $repo, $repoConfig) { $config['repositories'][$repo] = $repoConfig; }); } public function removeRepository($name) { - return $this->manipulateJson('removeRepository', $name, function (&$config, $repo) { + $this->manipulateJson('removeRepository', $name, function (&$config, $repo) { unset($config['repositories'][$repo]); }); } @@ -51,7 +51,7 @@ class JsonConfigSource implements ConfigSourceInterface public function removeConfigSetting($name) { - return $this->manipulateJson('removeConfigSetting', $name, function (&$config, $key) { + $this->manipulateJson('removeConfigSetting', $name, function (&$config, $key) { unset($config['config'][$key]); }); } diff --git a/tests/Composer/Test/Mock/RemoteFilesystemMock.php b/tests/Composer/Test/Mock/RemoteFilesystemMock.php index 444c557e2..caf1c5e65 100644 --- a/tests/Composer/Test/Mock/RemoteFilesystemMock.php +++ b/tests/Composer/Test/Mock/RemoteFilesystemMock.php @@ -28,7 +28,7 @@ class RemoteFilesystemMock extends RemoteFilesystem $this->contentMap = $contentMap; } - public function getContents($originUrl, $fileUrl, $progress = true) + public function getContents($originUrl, $fileUrl, $progress = true, $options = array()) { if (!empty($this->contentMap[$fileUrl])) { return $this->contentMap[$fileUrl]; diff --git a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php index d8fdebd07..2cd9b2364 100644 --- a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php @@ -68,14 +68,22 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase ->with($this->equalTo('Password: ')) ->will($this->returnValue('somepassword')); - $io->expects($this->once()) + $io->expects($this->any()) ->method('setAuthorization') - ->with($this->equalTo('github.com'), 'someuser', 'somepassword'); + ->with($this->equalTo('github.com'), $this->matchesRegularExpression('{someuser|abcdef}'), $this->matchesRegularExpression('{somepassword|x-oauth-basic}')); $remoteFilesystem->expects($this->at(1)) + ->method('getContents') + ->with($this->equalTo('github.com'), $this->equalTo('https://api.github.com/authorizations'), $this->equalTo(false)) + ->will($this->returnValue('{"token": "abcdef"}')); + + $remoteFilesystem->expects($this->at(2)) ->method('getContents') ->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false)) - ->will($this->returnValue('{"master_branch": "test_master"}')); + ->will($this->returnValue('{"master_branch": "test_master", "private": true}')); + + $configSource = $this->getMock('Composer\Config\ConfigSourceInterface'); + $this->config->setConfigSource($configSource); $gitHubDriver = new GitHubDriver($repoUrl, $io, $this->config, $process, $remoteFilesystem); $gitHubDriver->initialize(); diff --git a/tests/Composer/Test/Util/RemoteFilesystemTest.php b/tests/Composer/Test/Util/RemoteFilesystemTest.php index 4dd3aa0e7..def4b14c4 100644 --- a/tests/Composer/Test/Util/RemoteFilesystemTest.php +++ b/tests/Composer/Test/Util/RemoteFilesystemTest.php @@ -25,7 +25,7 @@ class RemoteFilesystemTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(false)) ; - $res = $this->callGetOptionsForUrl($io, array('http://example.org')); + $res = $this->callGetOptionsForUrl($io, array('http://example.org', array())); $this->assertTrue(isset($res['http']['header']) && false !== strpos($res['http']['header'], 'User-Agent'), 'getOptions must return an array with a header containing a User-Agent'); } @@ -43,7 +43,7 @@ class RemoteFilesystemTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(array('username' => 'login', 'password' => 'password'))) ; - $options = $this->callGetOptionsForUrl($io, array('http://example.org')); + $options = $this->callGetOptionsForUrl($io, array('http://example.org', array())); $this->assertContains('Authorization: Basic', $options['http']['header']); } @@ -60,10 +60,28 @@ class RemoteFilesystemTest extends \PHPUnit_Framework_TestCase 'allow_self_signed' => true, )); - $res = $this->callGetOptionsForUrl($io, array('https://example.org'), $streamOptions); + $res = $this->callGetOptionsForUrl($io, array('https://example.org', array()), $streamOptions); $this->assertTrue(isset($res['ssl']) && isset($res['ssl']['allow_self_signed']) && true === $res['ssl']['allow_self_signed'], 'getOptions must return an array with a allow_self_signed set to true'); } + public function testGetOptionsForUrlWithCallOptionsKeepsHeader() + { + $io = $this->getMock('Composer\IO\IOInterface'); + $io + ->expects($this->once()) + ->method('hasAuthorization') + ->will($this->returnValue(true)) + ; + + $streamOptions = array('http' => array( + 'header' => 'Foo: bar', + )); + + $res = $this->callGetOptionsForUrl($io, array('https://example.org', $streamOptions)); + $this->assertTrue(isset($res['http']['header']), 'getOptions must return an array with a http.header key'); + $this->assertGreaterThan(strlen('Foo: bar'), strlen($res['http']['header'])); + } + public function testCallbackGetFileSize() { $fs = new RemoteFilesystem($this->getMock('Composer\IO\IOInterface'));