XzDownloaderTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Downloader;
  12. use Composer\Downloader\XzDownloader;
  13. use Composer\Util\Filesystem;
  14. class XzDownloaderTest extends \PHPUnit_Framework_TestCase
  15. {
  16. /**
  17. * @var Filesystem
  18. */
  19. private $fs;
  20. /**
  21. * @var string
  22. */
  23. private $testName;
  24. public function setUp()
  25. {
  26. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  27. $this->markTestSkipped('Skip test on Windows');
  28. }
  29. $this->testName = sys_get_temp_dir().'/composer-xz-test-vendor';
  30. }
  31. public function tearDown()
  32. {
  33. $this->fs = new Filesystem;
  34. $this->fs->removeDirectory($this->testName);
  35. }
  36. public function testErrorMessages()
  37. {
  38. $packageMock = $this->getMock('Composer\Package\PackageInterface');
  39. $packageMock->expects($this->any())
  40. ->method('getDistUrl')
  41. ->will($this->returnValue($distUrl = 'file://'.__FILE__))
  42. ;
  43. $packageMock->expects($this->any())
  44. ->method('getDistUrls')
  45. ->will($this->returnValue(array($distUrl)))
  46. ;
  47. $packageMock->expects($this->atLeastOnce())
  48. ->method('getTransportOptions')
  49. ->will($this->returnValue(array()))
  50. ;
  51. $io = $this->getMock('Composer\IO\IOInterface');
  52. $config = $this->getMock('Composer\Config');
  53. $config->expects($this->any())
  54. ->method('get')
  55. ->with('vendor-dir')
  56. ->will($this->returnValue($this->testName));
  57. $downloader = new XzDownloader($io, $config);
  58. try {
  59. $downloader->download($packageMock, sys_get_temp_dir().'/composer-xz-test');
  60. $this->fail('Download of invalid tarball should throw an exception');
  61. } catch (\RuntimeException $e) {
  62. $this->assertContains('File format not recognized', $e->getMessage());
  63. }
  64. }
  65. }