1
0
Fork 0

Fix tests

pull/1191/merge
Jordi Boggiano 2012-10-18 18:43:31 +02:00
parent cf0753e062
commit e0ce22f7cc
4 changed files with 36 additions and 10 deletions

View File

@ -30,14 +30,14 @@ class JsonConfigSource implements ConfigSourceInterface
public function addRepository($name, $config) 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; $config['repositories'][$repo] = $repoConfig;
}); });
} }
public function removeRepository($name) public function removeRepository($name)
{ {
return $this->manipulateJson('removeRepository', $name, function (&$config, $repo) { $this->manipulateJson('removeRepository', $name, function (&$config, $repo) {
unset($config['repositories'][$repo]); unset($config['repositories'][$repo]);
}); });
} }
@ -51,7 +51,7 @@ class JsonConfigSource implements ConfigSourceInterface
public function removeConfigSetting($name) public function removeConfigSetting($name)
{ {
return $this->manipulateJson('removeConfigSetting', $name, function (&$config, $key) { $this->manipulateJson('removeConfigSetting', $name, function (&$config, $key) {
unset($config['config'][$key]); unset($config['config'][$key]);
}); });
} }

View File

@ -28,7 +28,7 @@ class RemoteFilesystemMock extends RemoteFilesystem
$this->contentMap = $contentMap; $this->contentMap = $contentMap;
} }
public function getContents($originUrl, $fileUrl, $progress = true) public function getContents($originUrl, $fileUrl, $progress = true, $options = array())
{ {
if (!empty($this->contentMap[$fileUrl])) { if (!empty($this->contentMap[$fileUrl])) {
return $this->contentMap[$fileUrl]; return $this->contentMap[$fileUrl];

View File

@ -68,14 +68,22 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
->with($this->equalTo('Password: ')) ->with($this->equalTo('Password: '))
->will($this->returnValue('somepassword')); ->will($this->returnValue('somepassword'));
$io->expects($this->once()) $io->expects($this->any())
->method('setAuthorization') ->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)) $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') ->method('getContents')
->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false)) ->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 = new GitHubDriver($repoUrl, $io, $this->config, $process, $remoteFilesystem);
$gitHubDriver->initialize(); $gitHubDriver->initialize();

View File

@ -25,7 +25,7 @@ class RemoteFilesystemTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(false)) ->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'); $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'))) ->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']); $this->assertContains('Authorization: Basic', $options['http']['header']);
} }
@ -60,10 +60,28 @@ class RemoteFilesystemTest extends \PHPUnit_Framework_TestCase
'allow_self_signed' => true, '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'); $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() public function testCallbackGetFileSize()
{ {
$fs = new RemoteFilesystem($this->getMock('Composer\IO\IOInterface')); $fs = new RemoteFilesystem($this->getMock('Composer\IO\IOInterface'));