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

128 lines
3.9 KiB
PHP
Raw Normal View History

2022-02-23 15:58:18 +00:00
<?php declare(strict_types=1);
2015-10-13 09:34:02 +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\Config;
use Composer\IO\NullIO;
use Composer\Util\Svn;
2020-02-07 03:18:45 +00:00
use Composer\Test\TestCase;
class SvnTest extends TestCase
{
/**
* Test the credential string.
*
* @param string $url The SVN url.
* @param string $expect The expectation for the test.
*
* @dataProvider urlProvider
*/
2022-02-22 15:47:09 +00:00
public function testCredentials(string $url, string $expect): void
{
$svn = new Svn($url, new NullIO, new Config());
2013-02-20 15:50:26 +00:00
$reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialString');
$reflMethod->setAccessible(true);
self::assertEquals($expect, $reflMethod->invoke($svn));
2013-02-20 15:50:26 +00:00
}
public static function urlProvider(): array
2013-02-20 15:50:26 +00:00
{
2022-08-17 12:20:07 +00:00
return [
['http://till:test@svn.example.org/', self::getCmd(" --username 'till' --password 'test' ")],
2022-08-17 12:20:07 +00:00
['http://svn.apache.org/', ''],
['svn://johndoe@example.org', self::getCmd(" --username 'johndoe' --password '' ")],
2022-08-17 12:20:07 +00:00
];
}
public function testInteractiveString(): void
{
$url = 'http://svn.example.org';
$svn = new Svn($url, new NullIO(), new Config());
2013-02-20 15:50:26 +00:00
$reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCommand');
$reflMethod->setAccessible(true);
self::assertEquals(
self::getCmd("svn ls --non-interactive -- 'http://svn.example.org'"),
2022-08-17 12:20:07 +00:00
$reflMethod->invokeArgs($svn, ['svn ls', $url])
);
}
2013-02-20 15:50:26 +00:00
public function testCredentialsFromConfig(): void
{
$url = 'http://svn.apache.org';
$config = new Config();
2022-08-17 12:20:07 +00:00
$config->merge([
'config' => [
'http-basic' => [
'svn.apache.org' => ['username' => 'foo', 'password' => 'bar'],
],
],
]);
$svn = new Svn($url, new NullIO, $config);
$reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialString');
$reflMethod->setAccessible(true);
self::assertEquals(self::getCmd(" --username 'foo' --password 'bar' "), $reflMethod->invoke($svn));
}
public function testCredentialsFromConfigWithCacheCredentialsTrue(): void
2014-09-15 11:21:33 +00:00
{
$url = 'http://svn.apache.org';
$config = new Config();
$config->merge(
2022-08-17 12:20:07 +00:00
[
'config' => [
'http-basic' => [
'svn.apache.org' => ['username' => 'foo', 'password' => 'bar'],
],
],
]
);
$svn = new Svn($url, new NullIO, $config);
$svn->setCacheCredentials(true);
$reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialString');
$reflMethod->setAccessible(true);
self::assertEquals(self::getCmd(" --username 'foo' --password 'bar' "), $reflMethod->invoke($svn));
}
public function testCredentialsFromConfigWithCacheCredentialsFalse(): void
2014-09-15 11:21:33 +00:00
{
$url = 'http://svn.apache.org';
$config = new Config();
$config->merge(
2022-08-17 12:20:07 +00:00
[
'config' => [
'http-basic' => [
'svn.apache.org' => ['username' => 'foo', 'password' => 'bar'],
],
],
]
);
$svn = new Svn($url, new NullIO, $config);
$svn->setCacheCredentials(false);
$reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialString');
$reflMethod->setAccessible(true);
self::assertEquals(self::getCmd(" --no-auth-cache --username 'foo' --password 'bar' "), $reflMethod->invoke($svn));
}
2012-06-14 10:10:01 +00:00
}