1
0
Fork 0
composer/tests/Composer/Test/Downloader/XzDownloaderTest.php

73 lines
2.0 KiB
PHP
Raw Normal View History

2022-02-23 15:58:18 +00:00
<?php declare(strict_types=1);
2015-11-03 22:20:23 +00:00
/*
* 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;
use Composer\Test\TestCase;
use Composer\Util\Filesystem;
use Composer\Util\Platform;
use Composer\Util\Loop;
use Composer\Util\HttpDownloader;
2015-11-03 22:20:23 +00:00
class XzDownloaderTest extends TestCase
2015-11-03 22:20:23 +00:00
{
/**
* @var Filesystem
*/
private $fs;
/**
* @var string
*/
2016-01-09 18:39:18 +00:00
private $testDir;
2021-12-08 16:03:05 +00:00
public function setUp(): void
2015-11-03 22:20:23 +00:00
{
if (Platform::isWindows()) {
2015-11-03 22:20:23 +00:00
$this->markTestSkipped('Skip test on Windows');
}
$this->testDir = self::getUniqueTmpDirectory();
}
protected function tearDown(): void
{
if (Platform::isWindows()) {
return;
}
parent::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(): void
2015-11-03 22:20:23 +00:00
{
$package = self::getPackage();
2022-02-22 15:47:09 +00:00
$package->setDistUrl($distUrl = 'file://'.__FILE__);
2015-11-03 22:20:23 +00:00
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
2022-02-22 15:47:09 +00:00
$config = $this->getConfig(['vendor-dir' => $this->testDir]);
$downloader = new XzDownloader($io, $config, $httpDownloader = new HttpDownloader($io, $config), null, null, null);
2015-11-03 22:20:23 +00:00
try {
$loop = new Loop($httpDownloader);
2022-02-22 15:47:09 +00:00
$promise = $downloader->download($package, $this->testDir.'/install-path');
2022-08-17 12:20:07 +00:00
$loop->wait([$promise]);
2022-02-22 15:47:09 +00:00
$downloader->install($package, $this->testDir.'/install-path');
2015-11-03 22:20:23 +00:00
$this->fail('Download of invalid tarball should throw an exception');
} catch (\RuntimeException $e) {
self::assertMatchesRegularExpression('/(File format not recognized|Unrecognized archive format)/i', $e->getMessage());
2015-11-03 22:20:23 +00:00
}
}
}