XzDownloaderTest.php 2.5 KB

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