From 879d34589b2c0c3f33a4ba5533e2e093f6503e2a Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 3 Nov 2015 23:20:23 +0100 Subject: [PATCH] XzDownloader test --- .../Test/Downloader/XzDownloaderTest.php | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/Composer/Test/Downloader/XzDownloaderTest.php diff --git a/tests/Composer/Test/Downloader/XzDownloaderTest.php b/tests/Composer/Test/Downloader/XzDownloaderTest.php new file mode 100644 index 000000000..02e6701a0 --- /dev/null +++ b/tests/Composer/Test/Downloader/XzDownloaderTest.php @@ -0,0 +1,57 @@ + + * Jordi Boggiano + * + * 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; + +class XzDownloaderTest extends \PHPUnit_Framework_TestCase +{ + public function setUp() + { + if (defined('PHP_WINDOWS_VERSION_BUILD')) { + $this->markTestSkipped('Skip test on Windows'); + } + } + + 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') + ->will($this->returnValue(sys_get_temp_dir().'/composer-xz-test-vendor')); + $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()); + } + } +}