ZipDownloaderTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. class ZipDownloaderTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function setUp()
  16. {
  17. if (!class_exists('ZipArchive')) {
  18. $this->markTestSkipped('zip extension missing');
  19. }
  20. }
  21. public function testErrorMessages()
  22. {
  23. $packageMock = $this->getMock('Composer\Package\PackageInterface');
  24. $packageMock->expects($this->any())
  25. ->method('getDistUrl')
  26. ->will($this->returnValue('file://'.__FILE__))
  27. ;
  28. $packageMock->expects($this->atLeastOnce())
  29. ->method('getTransportOptions')
  30. ->will($this->returnValue(array()))
  31. ;
  32. $io = $this->getMock('Composer\IO\IOInterface');
  33. $config = $this->getMock('Composer\Config');
  34. $config->expects($this->any())
  35. ->method('get')
  36. ->with('vendor-dir')
  37. ->will($this->returnValue(sys_get_temp_dir().'/composer-zip-test-vendor'));
  38. $downloader = new ZipDownloader($io, $config);
  39. try {
  40. $downloader->download($packageMock, sys_get_temp_dir().'/composer-zip-test');
  41. $this->fail('Download of invalid zip files should throw an exception');
  42. } catch (\UnexpectedValueException $e) {
  43. $this->assertContains('is not a zip archive', $e->getMessage());
  44. }
  45. }
  46. }