VersionControl_Git
[ class tree: VersionControl_Git ] [ index: VersionControl_Git ] [ all elements ]

Source for file VersionControl_Git_Util_CommandTest.php

Documentation is available at VersionControl_Git_Util_CommandTest.php

  1. <?php
  2.  
  3. chdir(dirname(__FILE__));
  4. set_include_path(get_include_path().PATH_SEPARATOR.realpath('../'));
  5.  
  6. require_once 'PHPUnit/Autoload.php';
  7. require_once 'VersionControl/Git.php';
  8.  
  9. require_once './checkFixtures.php';
  10.  
  11. {
  12.   public function getCommandString($arguments = array()$options = array())
  13.   {
  14.     return $this->createCommandString($arguments$options);
  15.   }
  16.  
  17.   public function getProperty($name)
  18.   {
  19.     return $this->$name;
  20.   }
  21. }
  22.  
  23. class VersionControl_Git_Util_CommandTest extends PHPUnit_Framework_TestCase
  24. {
  25.   public function testConstruct()
  26.   {
  27.     $git = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  28.     $instance = new DummyGitCommand($git);
  29.  
  30.     $this->assertTrue($instance instanceof VersionControl_Git_Util_Command);
  31.   }
  32.  
  33.   public function testSetSubCommand()
  34.   {
  35.     $git = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  36.     $instance = new DummyGitCommand($git);
  37.  
  38.     $this->assertEquals($instance->getProperty('subCommand')'');
  39.  
  40.     $instance->setSubCommand('subcommand');
  41.  
  42.     $this->assertEquals($instance->getProperty('subCommand')'subcommand');
  43.   }
  44.  
  45.   public function testSetOptions()
  46.   {
  47.     $git = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  48.     $instance = new DummyGitCommand($git);
  49.  
  50.     $this->assertEquals($instance->getProperty('options')array());
  51.  
  52.     $options1 = array('option1' => time(* 1'option2' => time(* 2);
  53.     $instance->setOptions($options1);
  54.     $this->assertEquals($instance->getProperty('options')$options1);
  55.  
  56.     $options2 = array('option3' => time(* 3'option4' => time(* 4);
  57.     $instance->setOptions($options2);
  58.     $this->assertEquals($instance->getProperty('options')$options2);
  59.   }
  60.  
  61.   public function testSetArguments()
  62.   {
  63.     $git = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  64.     $instance = new DummyGitCommand($git);
  65.  
  66.     $this->assertEquals($instance->getProperty('arguments')array());
  67.  
  68.     $arguments1 = array(time(* 1time(* 2);
  69.     $instance->setArguments($arguments1);
  70.     $this->assertEquals($instance->getProperty('arguments')$arguments1);
  71.  
  72.     $arguments2 = array(time(* 3time(* 4);
  73.     $instance->setArguments($arguments2);
  74.     $this->assertEquals($instance->getProperty('arguments')$arguments2);
  75.   }
  76.  
  77.   public function testSetOption()
  78.   {
  79.     $git = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  80.     $instance = new DummyGitCommand($git);
  81.  
  82.     $options1 = array('option1' => time(* 1'option2' => time(* 2);
  83.     $instance->setOptions($options1);
  84.     $this->assertEquals($instance->getProperty('options')$options1);
  85.  
  86.     $newOption time(* 3;
  87.     $instance->setOption('option1'$newOption);
  88.     $this->assertEquals($instance->getProperty('options')array('option1' => $newOption'option2' => $options1['option2']));
  89.   }
  90.  
  91.   public function testAddArgument()
  92.   {
  93.     $git = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  94.     $instance = new DummyGitCommand($git);
  95.  
  96.     $arguments = array(123);
  97.     $instance->setArguments($arguments);
  98.     $this->assertEquals($instance->getProperty('arguments')$arguments);
  99.  
  100.     $instance->addArgument(4);
  101.     $this->assertEquals($instance->getProperty('arguments')array(1234));
  102.   }
  103.  
  104.   public function testAddDoubleDash()
  105.   {
  106.     $git = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  107.     $instance = new DummyGitCommand($git);
  108.  
  109.     $this->assertEquals($instance->getProperty('doubleDash')false);
  110.     $instance->addDoubleDash(true);
  111.     $this->assertEquals($instance->getProperty('doubleDash')true);
  112.     $instance->addDoubleDash(false);
  113.     $this->assertEquals($instance->getProperty('doubleDash')false);
  114.   }
  115.  
  116.   public function testCreateCommandStringException()
  117.   {
  118.     $this->setExpectedException('VersionControl_Git_Exception');
  119.  
  120.     $git = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  121.     $instance = new DummyGitCommand($git);
  122.  
  123.     $instance->getCommandString();
  124.   }
  125.  
  126.   public function testCreateCommandString()
  127.   {
  128.     $git = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  129.     $i1 = new DummyGitCommand($git);
  130.  
  131.     $i1->setSubCommand('subcommand');
  132.  
  133.     $this->assertEquals($i1->getCommandString()'/usr/bin/git subcommand');
  134.     $this->assertEquals($i1->getCommandString(array('a1''a2'))'/usr/bin/git subcommand \'a1\' \'a2\'');
  135.     $this->assertEquals($i1->getCommandString(array()array('o1' => 'v1''o2' => true'o3' => false'o' => true))'/usr/bin/git subcommand --o1=\'v1\' --o2 -o');
  136.     $this->assertEquals($i1->getCommandString(array('a1''a2')array('o1' => 'v1''o2' => true'o3' => false'o' => true))'/usr/bin/git subcommand --o1=\'v1\' --o2 -o \'a1\' \'a2\'');
  137.  
  138.     $i2 = clone $i1;
  139.     $i2->setArguments(array('A1''A2'));
  140.  
  141.     $this->assertEquals($i2->getCommandString()'/usr/bin/git subcommand \'A1\' \'A2\'');
  142.     $this->assertEquals($i2->getCommandString(array('a1''a2'))'/usr/bin/git subcommand \'A1\' \'A2\' \'a1\' \'a2\'');
  143.     $this->assertEquals($i2->getCommandString(array()array('o1' => 'v1''o2' => true'o3' => false'o' => true))'/usr/bin/git subcommand --o1=\'v1\' --o2 -o \'A1\' \'A2\'');
  144.     $this->assertEquals($i2->getCommandString(array('a1''a2')array('o1' => 'v1''o2' => true'o3' => false'o' => true))'/usr/bin/git subcommand --o1=\'v1\' --o2 -o \'A1\' \'A2\' \'a1\' \'a2\'');
  145.  
  146.     $i3 = clone $i1;
  147.     $i3->setOptions(array('O1' => 'V1''o2' => 'V2'));
  148.  
  149.     $this->assertEquals($i3->getCommandString()'/usr/bin/git subcommand --O1=\'V1\' --o2=\'V2\'');
  150.     $this->assertEquals($i3->getCommandString(array('a1''a2'))'/usr/bin/git subcommand --O1=\'V1\' --o2=\'V2\' \'a1\' \'a2\'');
  151.     $this->assertEquals($i3->getCommandString(array()array('o1' => 'v1''o2' => true'o3' => false'o' => true))'/usr/bin/git subcommand --O1=\'V1\' --o2 --o1=\'v1\' -o');
  152.     $this->assertEquals($i3->getCommandString(array('a1''a2')array('o1' => 'v1''o2' => true'o3' => false'o' => true))'/usr/bin/git subcommand --O1=\'V1\' --o2 --o1=\'v1\' -o \'a1\' \'a2\'');
  153.  
  154.     $i4 = clone $i1;
  155.     $i4->addDoubleDash(true);
  156.  
  157.     $this->assertEquals($i4->getCommandString()'/usr/bin/git subcommand --');
  158.     $this->assertEquals($i4->getCommandString(array('a1''a2'))'/usr/bin/git subcommand \'a1\' \'a2\' --');
  159.     $this->assertEquals($i4->getCommandString(array()array('o1' => 'v1''o2' => true'o3' => false'o' => true))'/usr/bin/git subcommand --o1=\'v1\' --o2 -o --');
  160.     $this->assertEquals($i4->getCommandString(array('a1''a2')array('o1' => 'v1''o2' => true'o3' => false'o' => true))'/usr/bin/git subcommand --o1=\'v1\' --o2 -o \'a1\' \'a2\' --');
  161.   }
  162.  
  163.   public function testExecuteException()
  164.   {
  165.     $this->setExpectedException('VersionControl_Git_Exception');
  166.  
  167.     $git = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  168.     $i1 = new DummyGitCommand($git);
  169.  
  170.     $i1->setSubCommand('subcommand')
  171.       ->execute();
  172.   }
  173.  
  174.   public function testExecute()
  175.   {
  176.     $git = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  177.     $i1 = new DummyGitCommand($git);
  178.  
  179.     $result $i1->setSubCommand('log')
  180.       ->setOption('pretty''oneline')
  181.       ->setOption('grep''initial')
  182.       ->execute();
  183.  
  184.     $this->assertEquals(trim($result)'b8adc7214881bb71b9741b5d8228ebf346197d47 initial commit');
  185.   }
  186.  
  187.   public function testExecuteWithShortFormatOption()
  188.   {
  189.     $git = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  190.     $i1 = new DummyGitCommand($git);
  191.  
  192.     $result $i1->setSubCommand('log')
  193.       ->setOption('n''1')
  194.       ->setOption('pretty''oneline')
  195.       ->setOption('grep''initial')
  196.       ->execute();
  197.  
  198.     $this->assertEquals($i1->getCommandString()@System::which('git').' log -n\'1\' --pretty=\'oneline\' --grep=\'initial\'');
  199.     $this->assertEquals(trim($result)'b8adc7214881bb71b9741b5d8228ebf346197d47 initial commit');
  200.   }
  201. }

Documentation generated on Mon, 11 Mar 2019 15:43:05 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.