2012-03-22 16:16:41 +00:00
|
|
|
<?php
|
|
|
|
namespace Composer\Test\Util;
|
|
|
|
|
|
|
|
use Composer\IO\NullIO;
|
|
|
|
use Composer\Util\Svn;
|
|
|
|
|
2013-02-20 15:50:26 +00:00
|
|
|
class SvnTest extends \PHPUnit_Framework_TestCase
|
2012-03-22 16:16:41 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test the credential string.
|
|
|
|
*
|
|
|
|
* @param string $url The SVN url.
|
|
|
|
* @param string $expect The expectation for the test.
|
|
|
|
*
|
|
|
|
* @dataProvider urlProvider
|
|
|
|
*/
|
|
|
|
public function testCredentials($url, $expect)
|
|
|
|
{
|
|
|
|
$svn = new Svn($url, new NullIO);
|
2013-02-20 15:50:26 +00:00
|
|
|
$reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialString');
|
|
|
|
$reflMethod->setAccessible(true);
|
|
|
|
|
|
|
|
$this->assertEquals($expect, $reflMethod->invoke($svn));
|
|
|
|
}
|
2012-03-22 16:16:41 +00:00
|
|
|
|
2013-02-20 15:50:26 +00:00
|
|
|
/**
|
|
|
|
* Provide some examples for {@self::testCredentials()}.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function urlProvider()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('http://till:test@svn.example.org/', $this->getCmd(" --username 'till' --password 'test' ")),
|
|
|
|
array('http://svn.apache.org/', ''),
|
|
|
|
array('svn://johndoe@example.org', $this->getCmd(" --username 'johndoe' --password '' ")),
|
|
|
|
);
|
2012-03-22 16:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testInteractiveString()
|
|
|
|
{
|
|
|
|
$url = 'http://svn.example.org';
|
|
|
|
|
|
|
|
$svn = new Svn($url, new NullIO());
|
2013-02-20 15:50:26 +00:00
|
|
|
$reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCommand');
|
|
|
|
$reflMethod->setAccessible(true);
|
2012-03-22 16:16:41 +00:00
|
|
|
|
|
|
|
$this->assertEquals(
|
2013-02-20 15:50:26 +00:00
|
|
|
$this->getCmd("svn ls --non-interactive 'http://svn.example.org'"),
|
|
|
|
$reflMethod->invokeArgs($svn, array('svn ls', $url))
|
2012-03-22 16:16:41 +00:00
|
|
|
);
|
|
|
|
}
|
2013-02-20 15:50:26 +00:00
|
|
|
|
|
|
|
private function getCmd($cmd)
|
|
|
|
{
|
|
|
|
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
|
|
|
return strtr($cmd, "'", '"');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $cmd;
|
|
|
|
}
|
2012-06-14 10:10:01 +00:00
|
|
|
}
|