SvnDriverTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. * {@link \Composer\IO\NullIO} is always non-interactive.
  23. *
  24. * @return array
  25. */
  26. public static function urlProvider()
  27. {
  28. $nullIO = new \Composer\IO\NullIO;
  29. return array(
  30. array(
  31. 'http://till:test@svn.example.org/',
  32. " --no-auth-cache --username 'till' --password 'test' ",
  33. ),
  34. array(
  35. 'http://svn.apache.org/',
  36. '',
  37. ),
  38. array(
  39. 'svn://johndoe@example.org',
  40. " --no-auth-cache --username 'johndoe' --password '' ",
  41. ),
  42. );
  43. }
  44. /**
  45. * Test the credential string.
  46. *
  47. * @param string $url The SVN url.
  48. * @param string $expect The expectation for the test.
  49. *
  50. * @dataProvider urlProvider
  51. */
  52. public function testCredentials($url, $expect)
  53. {
  54. $svn = new SvnDriver($url, new \Composer\IO\NullIO);
  55. $this->assertEquals($expect, $svn->getSvnCredentialString());
  56. }
  57. /**
  58. * Test the execute method.
  59. */
  60. public function testExecute()
  61. {
  62. $this->markTestSkipped("Currently no way to mock the output value which is passed by reference.");
  63. $console = $this->getMock('Composer\IO\IOInterface');
  64. $console->expects($this->once())
  65. ->method('isInteractive')
  66. ->will($this->returnValue(true));
  67. $output = "svn: OPTIONS of 'http://corp.svn.local/repo':";
  68. $output .= " authorization failed: Could not authenticate to server:";
  69. $output .= " rejected Basic challenge (http://corp.svn.local/)";
  70. $process = $this->getMock('Composer\Util\ProcessExecutor');
  71. $process->expects($this->once())
  72. ->method('execute')
  73. ->will($this->returnValue(1));
  74. $svn = new SvnDriver('http://till:secret@corp.svn.local/repo', $console, $process);
  75. $svn->execute('svn ls', 'http://corp.svn.local/repo');
  76. }
  77. public function testInteractiveString()
  78. {
  79. $url = 'http://svn.example.org';
  80. $io = new \Composer\IO\NullIO; // non-interactive by design
  81. $svn = new SvnDriver($url, $io);
  82. $this->assertEquals(
  83. "svn ls --non-interactive 'http://svn.example.org'",
  84. $svn->getSvnCommand('svn ls', $url)
  85. );
  86. }
  87. }