ZipDownloaderTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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->any())
  50. ->method('get')
  51. ->with('vendor-dir')
  52. ->will($this->returnValue($this->testDir));
  53. $downloader = new ZipDownloader($io, $config);
  54. try {
  55. $downloader->download($packageMock, sys_get_temp_dir().'/composer-zip-test');
  56. $this->fail('Download of invalid zip files should throw an exception');
  57. } catch (\UnexpectedValueException $e) {
  58. $this->assertContains('is not a zip archive', $e->getMessage());
  59. }
  60. }
  61. }