ArchiveDownloaderTest.php 1.8 KB

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