XzDownloaderTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. use Composer\Util\RemoteFilesystem;
  15. class XzDownloaderTest extends \PHPUnit_Framework_TestCase
  16. {
  17. /**
  18. * @var Filesystem
  19. */
  20. private $fs;
  21. /**
  22. * @var string
  23. */
  24. private $testDir;
  25. public function setUp()
  26. {
  27. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  28. $this->markTestSkipped('Skip test on Windows');
  29. }
  30. $this->testDir = sys_get_temp_dir().'/composer-xz-test-vendor';
  31. }
  32. public function tearDown()
  33. {
  34. $this->fs = new Filesystem;
  35. $this->fs->removeDirectory($this->testDir);
  36. }
  37. public function testErrorMessages()
  38. {
  39. $packageMock = $this->getMock('Composer\Package\PackageInterface');
  40. $packageMock->expects($this->any())
  41. ->method('getDistUrl')
  42. ->will($this->returnValue($distUrl = 'file://'.__FILE__))
  43. ;
  44. $packageMock->expects($this->any())
  45. ->method('getDistUrls')
  46. ->will($this->returnValue(array($distUrl)))
  47. ;
  48. $packageMock->expects($this->atLeastOnce())
  49. ->method('getTransportOptions')
  50. ->will($this->returnValue(array()))
  51. ;
  52. $io = $this->getMock('Composer\IO\IOInterface');
  53. $config = $this->getMock('Composer\Config');
  54. $config->expects($this->any())
  55. ->method('get')
  56. ->with('vendor-dir')
  57. ->will($this->returnValue($this->testDir));
  58. $downloader = new XzDownloader($io, $config, null, null, null, new RemoteFilesystem($io));
  59. try {
  60. $downloader->download($packageMock, sys_get_temp_dir().'/composer-xz-test');
  61. $this->fail('Download of invalid tarball should throw an exception');
  62. } catch (\RuntimeException $e) {
  63. $this->assertContains('File format not recognized', $e->getMessage());
  64. }
  65. }
  66. }