SvnDriverTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. $input = new \Symfony\Component\Console\Input\ArrayInput(array('install'));
  30. $output = new \Symfony\Component\Console\Output\NullOutput;
  31. $helper = new \Symfony\Component\Console\Helper\HelperSet;
  32. $consoleInteractiveIO = new \Composer\IO\ConsoleIO($input, $output, $helper);
  33. return array(
  34. array(
  35. 'http://till:test@svn.example.org/',
  36. " --no-auth-cache --username 'till' --password 'test' ",
  37. $nullIO,
  38. ),
  39. array(
  40. 'http://svn.apache.org/',
  41. '',
  42. $nullIO,
  43. ),
  44. array(
  45. 'svn://johndoe@example.org',
  46. " --no-auth-cache --username 'johndoe' --password '' ",
  47. $nullIO,
  48. ),
  49. array(
  50. 'https://till:secret@corp.svn.local/project1',
  51. " --username 'till' --password 'secret' ",
  52. $consoleInteractiveIO,
  53. ),
  54. );
  55. }
  56. /**
  57. * Test the credential string.
  58. *
  59. * @param string $url The SVN url.
  60. * @param string $expect The expectation for the test.
  61. * @param string $ioClass The IO interface.
  62. *
  63. * @dataProvider urlProvider
  64. */
  65. public function testCredentials($url, $expect, \Composer\IO\IOInterface $io)
  66. {
  67. $svn = new SvnDriver($url, $io);
  68. $this->assertEquals($expect, $svn->getSvnCredentialString());
  69. }
  70. public function testInteractiveString()
  71. {
  72. $url = 'http://svn.example.org';
  73. $io = new \Composer\IO\NullIO; // non-interactive by design
  74. $svn = new SvnDriver($url, $io);
  75. $this->assertEquals(
  76. "svn ls --non-interactive 'http://svn.example.org'",
  77. $svn->getSvnCommand('svn ls', $url)
  78. );
  79. }
  80. }