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