SvnDriverTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Repository\Vcs;
  12. use Composer\Repository\Vcs\SvnDriver;
  13. use Composer\IO\NullIO;
  14. /**
  15. * @author Till Klampaeckel <till@php.net>
  16. */
  17. class SvnDriverTest extends \PHPUnit_Framework_TestCase
  18. {
  19. /**
  20. * Provide some examples for {@self::testCredentials()}.
  21. *
  22. * @return array
  23. */
  24. public function urlProvider()
  25. {
  26. return array(
  27. array('http://till:test@svn.example.org/', $this->getCmd(" --no-auth-cache --username 'till' --password 'test' ")),
  28. array('http://svn.apache.org/', ''),
  29. array('svn://johndoe@example.org', $this->getCmd(" --no-auth-cache --username 'johndoe' --password '' ")),
  30. );
  31. }
  32. /**
  33. * Test the credential string.
  34. *
  35. * @param string $url The SVN url.
  36. * @param string $expect The expectation for the test.
  37. *
  38. * @dataProvider urlProvider
  39. */
  40. public function testCredentials($url, $expect)
  41. {
  42. $svn = new SvnDriver($url, new NullIO);
  43. $this->assertEquals($expect, $svn->getSvnCredentialString());
  44. }
  45. /**
  46. * Test the execute method.
  47. */
  48. public function testExecute()
  49. {
  50. $this->markTestIncomplete("Currently no way to mock the output value which is passed by reference.");
  51. $console = $this->getMock('Composer\IO\IOInterface');
  52. $console->expects($this->once())
  53. ->method('isInteractive')
  54. ->will($this->returnValue(true));
  55. $output = "svn: OPTIONS of 'http://corp.svn.local/repo':";
  56. $output .= " authorization failed: Could not authenticate to server:";
  57. $output .= " rejected Basic challenge (http://corp.svn.local/)";
  58. $process = $this->getMock('Composer\Util\ProcessExecutor');
  59. $process->expects($this->once())
  60. ->method('execute')
  61. ->will($this->returnValue(1));
  62. $svn = new SvnDriver('http://till:secret@corp.svn.local/repo', $console, $process);
  63. $svn->execute('svn ls', 'http://corp.svn.local/repo');
  64. }
  65. public function testInteractiveString()
  66. {
  67. $url = 'http://svn.example.org';
  68. $io = new \Composer\IO\NullIO; // non-interactive by design
  69. $svn = new SvnDriver($url, $io);
  70. $this->assertEquals(
  71. "svn ls --non-interactive 'http://svn.example.org'",
  72. $svn->getSvnCommand('svn ls', $url)
  73. );
  74. }
  75. private function getCmd($cmd)
  76. {
  77. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  78. return strtr($cmd, "'", '"');
  79. }
  80. return $cmd;
  81. }
  82. public static function supportProvider()
  83. {
  84. return array(
  85. array('http://svn.apache.org', true),
  86. array('https://svn.sf.net', true),
  87. array('svn://example.org', true),
  88. array('svn+ssh://example.org', true),
  89. array('file:///d:/repository_name/project', true),
  90. array('file:///repository_name/project', true),
  91. array('/absolute/path', true),
  92. );
  93. }
  94. /**
  95. * Nail a bug in {@link SvnDriver::support()}.
  96. *
  97. * @dataProvider supportProvider
  98. */
  99. public function testSupport($url, $assertion)
  100. {
  101. if ($assertion === true) {
  102. $this->assertTrue(SvnDriver::supports($url));
  103. } else {
  104. $this->assertFalse(SvnDriver::supports($url));
  105. }
  106. }
  107. }