1
0
Fork 0
composer/tests/Composer/Test/Util/HttpDownloaderTest.php

86 lines
2.8 KiB
PHP
Raw Normal View History

2022-02-23 15:58:18 +00:00
<?php declare(strict_types=1);
2018-11-16 13:43:25 +00:00
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test\Util;
use Composer\IO\BufferIO;
2018-11-16 13:43:25 +00:00
use Composer\Util\HttpDownloader;
use PHPUnit\Framework\TestCase;
class HttpDownloaderTest extends TestCase
{
2021-10-27 14:18:46 +00:00
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Config
*/
2018-11-16 13:43:25 +00:00
private function getConfigMock()
{
$config = $this->getMockBuilder('Composer\Config')->getMock();
$config->expects($this->any())
->method('get')
2022-08-17 12:20:07 +00:00
->will($this->returnCallback(static function ($key) {
2018-11-16 13:43:25 +00:00
if ($key === 'github-domains' || $key === 'gitlab-domains') {
2022-08-17 12:20:07 +00:00
return [];
2018-11-16 13:43:25 +00:00
}
}));
return $config;
}
/**
* @group slow
*/
public function testCaptureAuthenticationParamsFromUrl(): void
2018-11-16 13:43:25 +00:00
{
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$io->expects($this->once())
->method('setAuthentication')
->with($this->equalTo('github.com'), $this->equalTo('user'), $this->equalTo('pass'));
$fs = new HttpDownloader($io, $this->getConfigMock());
try {
$fs->get('https://user:pass@github.com/composer/composer/404');
} catch (\Composer\Downloader\TransportException $e) {
self::assertNotEquals(200, $e->getCode());
2018-11-16 13:43:25 +00:00
}
}
public function testOutputWarnings(): void
{
$io = new BufferIO();
2022-08-17 12:20:07 +00:00
HttpDownloader::outputWarnings($io, '$URL', []);
self::assertSame('', $io->getOutput());
2022-08-17 12:20:07 +00:00
HttpDownloader::outputWarnings($io, '$URL', [
'warning' => 'old warning msg',
'warning-versions' => '>=2.0',
'info' => 'old info msg',
'info-versions' => '>=2.0',
2022-08-17 12:20:07 +00:00
'warnings' => [
['message' => 'should not appear', 'versions' => '<2.2'],
['message' => 'visible warning', 'versions' => '>=2.2-dev'],
],
'infos' => [
['message' => 'should not appear', 'versions' => '<2.2'],
['message' => 'visible info', 'versions' => '>=2.2-dev'],
],
]);
// the <info> tag are consumed by the OutputFormatter, but not <warning> as that is not a default output format
self::assertSame(
2021-11-24 15:19:37 +00:00
'<warning>Warning from $URL: old warning msg</warning>'.PHP_EOL.
'Info from $URL: old info msg'.PHP_EOL.
'<warning>Warning from $URL: visible warning</warning>'.PHP_EOL.
'Info from $URL: visible info'.PHP_EOL,
$io->getOutput()
);
}
2018-11-16 13:43:25 +00:00
}