SvnDriverTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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\Config;
  14. use Composer\TestCase;
  15. use Composer\Util\Filesystem;
  16. use Composer\Util\Platform;
  17. class SvnDriverTest extends TestCase
  18. {
  19. protected $home;
  20. protected $config;
  21. public function setUp()
  22. {
  23. $this->home = $this->getUniqueTmpDirectory();
  24. $this->config = new Config();
  25. $this->config->merge(array(
  26. 'config' => array(
  27. 'home' => $this->home,
  28. ),
  29. ));
  30. }
  31. public function tearDown()
  32. {
  33. $fs = new Filesystem();
  34. $fs->removeDirectory($this->home);
  35. }
  36. /**
  37. * @expectedException RuntimeException
  38. */
  39. public function testWrongCredentialsInUrl()
  40. {
  41. $console = $this->getMock('Composer\IO\IOInterface');
  42. $output = "svn: OPTIONS of 'https://corp.svn.local/repo':";
  43. $output .= " authorization failed: Could not authenticate to server:";
  44. $output .= " rejected Basic challenge (https://corp.svn.local/)";
  45. $process = $this->getMock('Composer\Util\ProcessExecutor');
  46. $process->expects($this->at(1))
  47. ->method('execute')
  48. ->will($this->returnValue(1));
  49. $process->expects($this->exactly(7))
  50. ->method('getErrorOutput')
  51. ->will($this->returnValue($output));
  52. $process->expects($this->at(2))
  53. ->method('execute')
  54. ->will($this->returnValue(0));
  55. $repoConfig = array(
  56. 'url' => 'https://till:secret@corp.svn.local/repo',
  57. );
  58. $svn = new SvnDriver($repoConfig, $console, $this->config, $process);
  59. $svn->initialize();
  60. }
  61. private function getCmd($cmd)
  62. {
  63. if (Platform::isWindows()) {
  64. return strtr($cmd, "'", '"');
  65. }
  66. return $cmd;
  67. }
  68. public static function supportProvider()
  69. {
  70. return array(
  71. array('http://svn.apache.org', true),
  72. array('https://svn.sf.net', true),
  73. array('svn://example.org', true),
  74. array('svn+ssh://example.org', true),
  75. );
  76. }
  77. /**
  78. * @dataProvider supportProvider
  79. */
  80. public function testSupport($url, $assertion)
  81. {
  82. $config = new Config();
  83. $result = SvnDriver::supports($this->getMock('Composer\IO\IOInterface'), $config, $url);
  84. $this->assertEquals($assertion, $result);
  85. }
  86. }