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;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2015-12-14 14:35:27 +00:00
|
|
|
use Composer\Util\Filesystem;
|
2016-02-03 21:39:16 +00:00
|
|
|
use Composer\Util\Platform;
|
2019-01-17 16:12:33 +00:00
|
|
|
use Composer\Util\Loop;
|
2018-10-31 11:44:54 +00:00
|
|
|
use Composer\Util\HttpDownloader;
|
2015-11-03 22:20:23 +00:00
|
|
|
|
2016-01-21 12:01:55 +00:00
|
|
|
class XzDownloaderTest extends TestCase
|
2015-11-03 22:20:23 +00:00
|
|
|
{
|
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()
|
|
|
|
{
|
2016-02-03 21:39:16 +00:00
|
|
|
if (Platform::isWindows()) {
|
2015-11-03 22:20:23 +00:00
|
|
|
$this->markTestSkipped('Skip test on Windows');
|
|
|
|
}
|
2016-01-21 12:01:55 +00:00
|
|
|
$this->testDir = $this->getUniqueTmpDirectory();
|
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()
|
|
|
|
{
|
2018-04-12 08:24:56 +00:00
|
|
|
$packageMock = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock();
|
2015-11-03 22:20:23 +00:00
|
|
|
$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()))
|
|
|
|
;
|
|
|
|
|
2018-04-12 08:24:56 +00:00
|
|
|
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
|
|
|
$config = $this->getMockBuilder('Composer\Config')->getMock();
|
2015-11-03 22:20:23 +00:00
|
|
|
$config->expects($this->any())
|
|
|
|
->method('get')
|
|
|
|
->with('vendor-dir')
|
2016-01-09 18:39:18 +00:00
|
|
|
->will($this->returnValue($this->testDir));
|
2019-01-17 16:12:33 +00:00
|
|
|
$downloader = new XzDownloader($io, $config, $httpDownloader = new HttpDownloader($io, $this->getMockBuilder('Composer\Config')->getMock()), null, null, null);
|
2015-11-03 22:20:23 +00:00
|
|
|
|
|
|
|
try {
|
2019-01-17 16:12:33 +00:00
|
|
|
$loop = new Loop($httpDownloader);
|
2020-06-05 06:33:44 +00:00
|
|
|
$promise = $downloader->download($packageMock, $this->testDir.'/install-path');
|
2019-01-17 16:12:33 +00:00
|
|
|
$loop->wait(array($promise));
|
2020-03-28 19:38:50 +00:00
|
|
|
$downloader->install($packageMock, $this->testDir.'/install-path');
|
2019-01-17 16:12:33 +00:00
|
|
|
|
2015-11-03 22:20:23 +00:00
|
|
|
$this->fail('Download of invalid tarball should throw an exception');
|
|
|
|
} catch (\RuntimeException $e) {
|
2020-09-11 09:27:26 +00:00
|
|
|
$this->assertMatchesRegularExpression('/(File format not recognized|Unrecognized archive format)/i', $e->getMessage());
|
2015-11-03 22:20:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|