SvnDriverTest.php 2.6 KB

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