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