ArchiveDownloaderTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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\Util\Filesystem;
  13. class ArchiveDownloaderTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testGetFileName()
  16. {
  17. $packageMock = $this->getMock('Composer\Package\PackageInterface');
  18. $packageMock->expects($this->any())
  19. ->method('getDistUrl')
  20. ->will($this->returnValue('http://example.com/script.js'))
  21. ;
  22. $downloader = $this->getMockForAbstractClass('Composer\Downloader\ArchiveDownloader', array($this->getMock('Composer\IO\IOInterface')));
  23. $method = new \ReflectionMethod($downloader, 'getFileName');
  24. $method->setAccessible(true);
  25. $first = $method->invoke($downloader, $packageMock, '/path');
  26. $this->assertRegExp('#/path/[a-z0-9]+\.js#', $first);
  27. $this->assertSame($first, $method->invoke($downloader, $packageMock, '/path'));
  28. }
  29. public function testProcessUrl()
  30. {
  31. $downloader = $this->getMockForAbstractClass('Composer\Downloader\ArchiveDownloader', array($this->getMock('Composer\IO\IOInterface')));
  32. $method = new \ReflectionMethod($downloader, 'processUrl');
  33. $method->setAccessible(true);
  34. $expected = 'https://github.com/composer/composer/zipball/master';
  35. $url = $method->invoke($downloader, $expected);
  36. if (extension_loaded('openssl')) {
  37. $this->assertEquals($expected, $url);
  38. } else {
  39. $this->assertEquals('http://nodeload.github.com/composer/composer/zipball/master', $url);
  40. }
  41. }
  42. }