HttpDownloaderTest.php 1.4 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\Util;
  12. use Composer\Util\HttpDownloader;
  13. use PHPUnit\Framework\TestCase;
  14. class HttpDownloaderTest extends TestCase
  15. {
  16. private function getConfigMock()
  17. {
  18. $config = $this->getMockBuilder('Composer\Config')->getMock();
  19. $config->expects($this->any())
  20. ->method('get')
  21. ->will($this->returnCallback(function ($key) {
  22. if ($key === 'github-domains' || $key === 'gitlab-domains') {
  23. return array();
  24. }
  25. }));
  26. return $config;
  27. }
  28. /**
  29. * @group slow
  30. */
  31. public function testCaptureAuthenticationParamsFromUrl()
  32. {
  33. $io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
  34. $io->expects($this->once())
  35. ->method('setAuthentication')
  36. ->with($this->equalTo('github.com'), $this->equalTo('user'), $this->equalTo('pass'));
  37. $fs = new HttpDownloader($io, $this->getConfigMock());
  38. try {
  39. $fs->get('https://user:pass@github.com/composer/composer/404');
  40. } catch (\Composer\Downloader\TransportException $e) {
  41. $this->assertNotEquals(200, $e->getCode());
  42. }
  43. }
  44. }