mirror of
https://github.com/composer/composer
synced 2025-05-09 00:22:53 +00:00
Port/extract most behavior of RemoteFilesystem to CurlDownloader
This commit is contained in:
parent
4a8a1cb0c9
commit
fd11cf3618
8 changed files with 518 additions and 319 deletions
|
@ -17,6 +17,20 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
class RemoteFilesystemTest extends TestCase
|
||||
{
|
||||
private function getConfigMock()
|
||||
{
|
||||
$config = $this->getMockBuilder('Composer\Config')->getMock();
|
||||
$config->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnCallback(function ($key) {
|
||||
if ($key === 'github-domains' || $key === 'gitlab-domains') {
|
||||
return array();
|
||||
}
|
||||
}));
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function testGetOptionsForUrl()
|
||||
{
|
||||
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
||||
|
@ -101,7 +115,7 @@ class RemoteFilesystemTest extends TestCase
|
|||
|
||||
public function testCallbackGetFileSize()
|
||||
{
|
||||
$fs = new RemoteFilesystem($this->getMockBuilder('Composer\IO\IOInterface')->getMock());
|
||||
$fs = new RemoteFilesystem($this->getMockBuilder('Composer\IO\IOInterface')->getMock(), $this->getConfigMock());
|
||||
$this->callCallbackGet($fs, STREAM_NOTIFY_FILE_SIZE_IS, 0, '', 0, 0, 20);
|
||||
$this->assertAttributeEquals(20, 'bytesMax', $fs);
|
||||
}
|
||||
|
@ -114,7 +128,7 @@ class RemoteFilesystemTest extends TestCase
|
|||
->method('overwriteError')
|
||||
;
|
||||
|
||||
$fs = new RemoteFilesystem($io);
|
||||
$fs = new RemoteFilesystem($io, $this->getConfigMock());
|
||||
$this->setAttribute($fs, 'bytesMax', 20);
|
||||
$this->setAttribute($fs, 'progress', true);
|
||||
|
||||
|
@ -124,7 +138,7 @@ class RemoteFilesystemTest extends TestCase
|
|||
|
||||
public function testCallbackGetPassesThrough404()
|
||||
{
|
||||
$fs = new RemoteFilesystem($this->getMockBuilder('Composer\IO\IOInterface')->getMock());
|
||||
$fs = new RemoteFilesystem($this->getMockBuilder('Composer\IO\IOInterface')->getMock(), $this->getConfigMock());
|
||||
|
||||
$this->assertNull($this->callCallbackGet($fs, STREAM_NOTIFY_FAILURE, 0, 'HTTP/1.1 404 Not Found', 404, 0, 0));
|
||||
}
|
||||
|
@ -139,7 +153,7 @@ class RemoteFilesystemTest extends TestCase
|
|||
->method('setAuthentication')
|
||||
->with($this->equalTo('github.com'), $this->equalTo('user'), $this->equalTo('pass'));
|
||||
|
||||
$fs = new RemoteFilesystem($io);
|
||||
$fs = new RemoteFilesystem($io, $this->getConfigMock());
|
||||
try {
|
||||
$fs->getContents('github.com', 'https://user:pass@github.com/composer/composer/404');
|
||||
} catch (\Exception $e) {
|
||||
|
@ -150,14 +164,14 @@ class RemoteFilesystemTest extends TestCase
|
|||
|
||||
public function testGetContents()
|
||||
{
|
||||
$fs = new RemoteFilesystem($this->getMockBuilder('Composer\IO\IOInterface')->getMock());
|
||||
$fs = new RemoteFilesystem($this->getMockBuilder('Composer\IO\IOInterface')->getMock(), $this->getConfigMock());
|
||||
|
||||
$this->assertContains('testGetContents', $fs->getContents('http://example.org', 'file://'.__FILE__));
|
||||
}
|
||||
|
||||
public function testCopy()
|
||||
{
|
||||
$fs = new RemoteFilesystem($this->getMockBuilder('Composer\IO\IOInterface')->getMock());
|
||||
$fs = new RemoteFilesystem($this->getMockBuilder('Composer\IO\IOInterface')->getMock(), $this->getConfigMock());
|
||||
|
||||
$file = tempnam(sys_get_temp_dir(), 'c');
|
||||
$this->assertTrue($fs->copy('http://example.org', 'file://'.__FILE__, $file));
|
||||
|
@ -218,7 +232,7 @@ class RemoteFilesystemTest extends TestCase
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$rfs = new RemoteFilesystem($io);
|
||||
$rfs = new RemoteFilesystem($io, $this->getConfigMock());
|
||||
$hostname = parse_url($url, PHP_URL_HOST);
|
||||
|
||||
$result = $rfs->getContents($hostname, $url, false);
|
||||
|
@ -240,14 +254,6 @@ class RemoteFilesystemTest extends TestCase
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$config = $this
|
||||
->getMockBuilder('Composer\Config')
|
||||
->getMock();
|
||||
$config
|
||||
->method('get')
|
||||
->withAnyParameters()
|
||||
->willReturn(array());
|
||||
|
||||
$domains = array();
|
||||
$io
|
||||
->expects($this->any())
|
||||
|
@ -267,7 +273,7 @@ class RemoteFilesystemTest extends TestCase
|
|||
'password' => '1A0yeK5Po3ZEeiiRiMWLivS0jirLdoGuaSGq9NvESFx1Fsdn493wUDXC8rz_1iKVRTl1GINHEUCsDxGh5lZ=',
|
||||
));
|
||||
|
||||
$rfs = new RemoteFilesystem($io, $config);
|
||||
$rfs = new RemoteFilesystem($io, $this->getConfigMock());
|
||||
$hostname = parse_url($url, PHP_URL_HOST);
|
||||
|
||||
$result = $rfs->getContents($hostname, $url, false);
|
||||
|
@ -278,7 +284,7 @@ class RemoteFilesystemTest extends TestCase
|
|||
|
||||
protected function callGetOptionsForUrl($io, array $args = array(), array $options = array(), $fileUrl = '')
|
||||
{
|
||||
$fs = new RemoteFilesystem($io, null, $options);
|
||||
$fs = new RemoteFilesystem($io, $this->getConfigMock(), $options);
|
||||
$ref = new \ReflectionMethod($fs, 'getOptionsForUrl');
|
||||
$prop = new \ReflectionProperty($fs, 'fileUrl');
|
||||
$ref->setAccessible(true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue