XzDownloaderTest.php 2.2 KB

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