ZipDownloaderTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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\ZipDownloader;
  13. use Composer\TestCase;
  14. use Composer\Util\Filesystem;
  15. class ZipDownloaderTest extends TestCase
  16. {
  17. /**
  18. * @var string
  19. */
  20. private $testDir;
  21. public function setUp()
  22. {
  23. if (!class_exists('ZipArchive')) {
  24. $this->markTestSkipped('zip extension missing');
  25. }
  26. $this->testDir = $this->getUniqueTmpDirectory();
  27. }
  28. public function tearDown()
  29. {
  30. $fs = new Filesystem;
  31. $fs->removeDirectory($this->testDir);
  32. }
  33. public function testErrorMessages()
  34. {
  35. $packageMock = $this->getMock('Composer\Package\PackageInterface');
  36. $packageMock->expects($this->any())
  37. ->method('getDistUrl')
  38. ->will($this->returnValue($distUrl = 'file://'.__FILE__))
  39. ;
  40. $packageMock->expects($this->any())
  41. ->method('getDistUrls')
  42. ->will($this->returnValue(array($distUrl)))
  43. ;
  44. $packageMock->expects($this->atLeastOnce())
  45. ->method('getTransportOptions')
  46. ->will($this->returnValue(array()))
  47. ;
  48. $io = $this->getMock('Composer\IO\IOInterface');
  49. $config = $this->getMock('Composer\Config');
  50. $config->expects($this->at(0))
  51. ->method('get')
  52. ->with('disable-tls')
  53. ->will($this->returnValue(false));
  54. $config->expects($this->at(1))
  55. ->method('get')
  56. ->with('cafile')
  57. ->will($this->returnValue(null));
  58. $config->expects($this->at(2))
  59. ->method('get')
  60. ->with('capath')
  61. ->will($this->returnValue(null));
  62. $config->expects($this->at(3))
  63. ->method('get')
  64. ->with('vendor-dir')
  65. ->will($this->returnValue($this->testDir));
  66. $downloader = new ZipDownloader($io, $config);
  67. try {
  68. $downloader->download($packageMock, sys_get_temp_dir().'/composer-zip-test');
  69. $this->fail('Download of invalid zip files should throw an exception');
  70. } catch (\UnexpectedValueException $e) {
  71. $this->assertContains('is not a zip archive', $e->getMessage());
  72. }
  73. }
  74. }