2012-03-29 13:34:57 +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\ZipDownloader;
|
|
|
|
|
|
|
|
class ZipDownloaderTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
if (!class_exists('ZipArchive')) {
|
|
|
|
$this->markTestSkipped('zip extension missing');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testErrorMessages()
|
|
|
|
{
|
|
|
|
$packageMock = $this->getMock('Composer\Package\PackageInterface');
|
|
|
|
$packageMock->expects($this->any())
|
|
|
|
->method('getDistUrl')
|
2013-07-01 23:45:43 +00:00
|
|
|
->will($this->returnValue($distUrl = 'file://'.__FILE__))
|
|
|
|
;
|
|
|
|
$packageMock->expects($this->any())
|
|
|
|
->method('getDistUrls')
|
|
|
|
->will($this->returnValue(array($distUrl)))
|
2012-03-29 13:34:57 +00:00
|
|
|
;
|
2013-08-19 07:38:25 +00:00
|
|
|
$packageMock->expects($this->atLeastOnce())
|
2014-05-07 16:25:28 +00:00
|
|
|
->method('getTransportOptions')
|
2013-08-19 07:38:25 +00:00
|
|
|
->will($this->returnValue(array()))
|
|
|
|
;
|
2012-03-29 13:34:57 +00:00
|
|
|
|
|
|
|
$io = $this->getMock('Composer\IO\IOInterface');
|
2012-10-21 15:56:57 +00:00
|
|
|
$config = $this->getMock('Composer\Config');
|
2013-07-31 18:33:20 +00:00
|
|
|
$config->expects($this->any())
|
2013-06-19 08:05:21 +00:00
|
|
|
->method('get')
|
|
|
|
->with('vendor-dir')
|
|
|
|
->will($this->returnValue(sys_get_temp_dir().'/composer-zip-test-vendor'));
|
2012-10-21 15:56:57 +00:00
|
|
|
$downloader = new ZipDownloader($io, $config);
|
2012-03-29 13:34:57 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
$downloader->download($packageMock, sys_get_temp_dir().'/composer-zip-test');
|
|
|
|
$this->fail('Download of invalid zip files should throw an exception');
|
|
|
|
} catch (\UnexpectedValueException $e) {
|
|
|
|
$this->assertContains('is not a zip archive', $e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|