SvnTest.php 1.7 KB

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