SvnDriverTest.php 2.6 KB

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