2015-11-03 22:20:23 +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\Downloader;
|
|
|
|
|
|
|
|
use Composer\Downloader\XzDownloader;
|
2015-12-14 14:35:27 +00:00
|
|
|
use Composer\Util\Filesystem;
|
2015-11-03 22:20:23 +00:00
|
|
|
|
|
|
|
class XzDownloaderTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2015-12-14 14:35:27 +00:00
|
|
|
/**
|
|
|
|
* @var Filesystem
|
|
|
|
*/
|
|
|
|
private $fs;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-01-09 18:39:18 +00:00
|
|
|
private $testDir;
|
2015-12-14 14:35:27 +00:00
|
|
|
|
2015-11-03 22:20:23 +00:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
|
|
|
$this->markTestSkipped('Skip test on Windows');
|
|
|
|
}
|
2016-01-09 18:39:18 +00:00
|
|
|
$this->testDir = sys_get_temp_dir().'/composer-xz-test-vendor';
|
2015-12-14 14:35:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
2015-12-14 15:50:04 +00:00
|
|
|
$this->fs = new Filesystem;
|
2016-01-09 18:39:18 +00:00
|
|
|
$this->fs->removeDirectory($this->testDir);
|
2015-11-03 22:20:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testErrorMessages()
|
|
|
|
{
|
|
|
|
$packageMock = $this->getMock('Composer\Package\PackageInterface');
|
|
|
|
$packageMock->expects($this->any())
|
|
|
|
->method('getDistUrl')
|
|
|
|
->will($this->returnValue($distUrl = 'file://'.__FILE__))
|
|
|
|
;
|
|
|
|
$packageMock->expects($this->any())
|
|
|
|
->method('getDistUrls')
|
|
|
|
->will($this->returnValue(array($distUrl)))
|
|
|
|
;
|
|
|
|
$packageMock->expects($this->atLeastOnce())
|
|
|
|
->method('getTransportOptions')
|
|
|
|
->will($this->returnValue(array()))
|
|
|
|
;
|
|
|
|
|
|
|
|
$io = $this->getMock('Composer\IO\IOInterface');
|
|
|
|
$config = $this->getMock('Composer\Config');
|
|
|
|
$config->expects($this->any())
|
|
|
|
->method('get')
|
|
|
|
->with('vendor-dir')
|
2016-01-09 18:39:18 +00:00
|
|
|
->will($this->returnValue($this->testDir));
|
2016-01-10 20:26:23 +00:00
|
|
|
$config->expects($this->any())
|
|
|
|
->method('get')
|
|
|
|
->with('disable-tls')
|
|
|
|
->will($this->returnValue(false));
|
2015-11-03 22:20:23 +00:00
|
|
|
$downloader = new XzDownloader($io, $config);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$downloader->download($packageMock, sys_get_temp_dir().'/composer-xz-test');
|
|
|
|
$this->fail('Download of invalid tarball should throw an exception');
|
|
|
|
} catch (\RuntimeException $e) {
|
|
|
|
$this->assertContains('File format not recognized', $e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|