XzDownloaderTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 $testDir;
  24. public function setUp()
  25. {
  26. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  27. $this->markTestSkipped('Skip test on Windows');
  28. }
  29. $this->testDir = sys_get_temp_dir().'/composer-xz-test-vendor';
  30. }
  31. public function tearDown()
  32. {
  33. $this->fs = new Filesystem;
  34. $this->fs->removeDirectory($this->testDir);
  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->testDir));
  57. $config->expects($this->any())
  58. ->method('get')
  59. ->with('disable-tls')
  60. ->will($this->returnValue(false));
  61. $downloader = new XzDownloader($io, $config);
  62. try {
  63. $downloader->download($packageMock, sys_get_temp_dir().'/composer-xz-test');
  64. $this->fail('Download of invalid tarball should throw an exception');
  65. } catch (\RuntimeException $e) {
  66. $this->assertContains('File format not recognized', $e->getMessage());
  67. }
  68. }
  69. }