XzDownloaderTest.php 2.3 KB

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