SvnTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Composer\Test\Util;
  3. use Composer\Config;
  4. use Composer\IO\NullIO;
  5. use Composer\Util\Svn;
  6. class SvnTest extends \PHPUnit_Framework_TestCase
  7. {
  8. /**
  9. * Test the credential string.
  10. *
  11. * @param string $url The SVN url.
  12. * @param string $expect The expectation for the test.
  13. *
  14. * @dataProvider urlProvider
  15. */
  16. public function testCredentials($url, $expect)
  17. {
  18. $svn = new Svn($url, new NullIO, new Config());
  19. $reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialString');
  20. $reflMethod->setAccessible(true);
  21. $this->assertEquals($expect, $reflMethod->invoke($svn));
  22. }
  23. /**
  24. * Provide some examples for {@self::testCredentials()}.
  25. *
  26. * @return array
  27. */
  28. public function urlProvider()
  29. {
  30. return array(
  31. array('http://till:test@svn.example.org/', $this->getCmd(" --username 'till' --password 'test' ")),
  32. array('http://svn.apache.org/', ''),
  33. array('svn://johndoe@example.org', $this->getCmd(" --username 'johndoe' --password '' ")),
  34. );
  35. }
  36. public function testInteractiveString()
  37. {
  38. $url = 'http://svn.example.org';
  39. $svn = new Svn($url, new NullIO(), new Config());
  40. $reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCommand');
  41. $reflMethod->setAccessible(true);
  42. $this->assertEquals(
  43. $this->getCmd("svn ls --non-interactive 'http://svn.example.org'"),
  44. $reflMethod->invokeArgs($svn, array('svn ls', $url))
  45. );
  46. }
  47. public function testCredentialsFromConfig()
  48. {
  49. $url = 'http://svn.apache.org';
  50. $config = new Config();
  51. $config->merge(array(
  52. 'config' => array(
  53. 'http-basic' => array(
  54. 'svn.apache.org' => array('username' => 'foo', 'password' => 'bar')
  55. )
  56. )
  57. ));
  58. $svn = new Svn($url, new NullIO, $config);
  59. $reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialString');
  60. $reflMethod->setAccessible(true);
  61. $this->assertEquals($this->getCmd(" --username 'foo' --password 'bar' "), $reflMethod->invoke($svn));
  62. }
  63. private function getCmd($cmd)
  64. {
  65. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  66. return strtr($cmd, "'", '"');
  67. }
  68. return $cmd;
  69. }
  70. }