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

Source for file VersionControl_GitTest.php

Documentation is available at VersionControl_GitTest.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. class VersionControl_GitTest extends PHPUnit_Framework_TestCase
  12. {
  13.   public function testConstructException()
  14.   {
  15.     $this->setExpectedException('VersionControl_Git_Exception');
  16.  
  17.     new VersionControl_Git('!This is not valid direcotry!');
  18.   }
  19.  
  20.   public function testConstruct()
  21.   {
  22.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  23.     $this->assertTrue($instance instanceof VersionControl_Git);
  24.   }
  25.  
  26.   public function testGetGitVersion()
  27.   {
  28.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  29.     $version $instance->getGitVersion();
  30.  
  31.     $this->assertTrue((bool)preg_match('/^[0-9]+\.[0-9]+\.[0-9]+/'$version));
  32.   }
  33.  
  34.   public function testGetCommits()
  35.   {
  36.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  37.     $commits $instance->getCommits();
  38.  
  39.     $this->assertTrue($commits[0instanceof VersionControl_Git_Object_Commit);
  40.     $this->assertEquals(count($commits)100);
  41.  
  42.     $commits $instance->getCommits('master'5);
  43.     $this->assertEquals(count($commits)5);
  44.  
  45.     $commits $instance->getCommits('master'1);
  46.     $this->assertEquals($commits[0]->id'4ed54abb8efca38a0c794ca414b1f296279e0d85');
  47.  
  48.     $commits $instance->getCommits('branch1'1);
  49.     $this->assertEquals($commits[0]->id'373efdec06a5847fd279d8c442dbfdd5df41e783');
  50.  
  51.     $commits $instance->getCommits('master'110);
  52.     $this->assertEquals($commits[0]->id'bf3488d82c09a749cefbb2633f9605b6ab5cf71e');
  53.   }
  54.  
  55.   public function testCreateClone()
  56.   {
  57.     $dirname $this->generateTmpDir();
  58.     $instance = new VersionControl_Git($dirname);
  59.     $instance->createClone('git://gist.github.com/265855.git');
  60.     $this->assertTrue(is_dir($dirname.DIRECTORY_SEPARATOR.'265855'));
  61.     $this->removeDirectory($dirname);
  62.  
  63.     $dirname $this->generateTmpDir();
  64.     $instance = new VersionControl_Git($dirname);
  65.     $instance->createClone('git://gist.github.com/265855.git'true);
  66.     if (version_compare('1.6.0-rc1'$instance->getGitVersion()'>='))
  67.     {
  68.       // see: http://git.kernel.org/?p=git/git.git;a=commit;h=6612f87
  69.       $this->assertTrue(is_file($dirname.DIRECTORY_SEPARATOR.'265855'.DIRECTORY_SEPARATOR.'HEAD'));
  70.     }
  71.     else
  72.     {
  73.       $this->assertTrue(is_file($dirname.DIRECTORY_SEPARATOR.'265855.git'.DIRECTORY_SEPARATOR.'HEAD'));
  74.     }
  75.     $this->removeDirectory($dirname);
  76.  
  77.     $dirname $this->generateTmpDir();
  78.     $instance = new VersionControl_Git($dirname);
  79.     $instance->createClone('git://gist.github.com/265855.git'true$dirname.DIRECTORY_SEPARATOR.'MY_WORKING_COPY');
  80.     $this->assertTrue(is_dir($dirname.DIRECTORY_SEPARATOR.'MY_WORKING_COPY'));
  81.     $this->assertTrue(realpath($instance->getDirectory()) === realpath($dirname.DIRECTORY_SEPARATOR.'MY_WORKING_COPY'));
  82.     $this->removeDirectory($dirname);
  83.  
  84.     $dirname $this->generateTmpDir();
  85.     $instance = new VersionControl_Git($dirname);
  86.     $instance->createClone('git://gist.github.com/265855.git'false$dirname);
  87.     $this->assertTrue(is_file($dirname.DIRECTORY_SEPARATOR.'patch_for_pecl_runkit.diff'));
  88.     $this->removeDirectory($dirname);
  89.   }
  90.  
  91.   public function testInitRepository()
  92.   {
  93.     $dirname $this->generateTmpDir();
  94.     $instance = new VersionControl_Git($dirname);
  95.     $instance->initRepository();
  96.     $this->assertTrue(is_dir($dirname.DIRECTORY_SEPARATOR.'.git'));
  97.     $this->removeDirectory($dirname);
  98.  
  99.     $dirname $this->generateTmpDir();
  100.     $instance = new VersionControl_Git($dirname);
  101.     $instance->initRepository(true);
  102.     $this->assertTrue(is_file($dirname.DIRECTORY_SEPARATOR.'HEAD'));
  103.     $this->removeDirectory($dirname);
  104.   }
  105.  
  106.   public function testInitialRepository()
  107.   {
  108.     $dirname $this->generateTmpDir();
  109.     $instance = new VersionControl_Git($dirname);
  110.     $instance->initialRepository();
  111.     $this->assertTrue(is_dir($dirname.DIRECTORY_SEPARATOR.'.git'));
  112.     $this->removeDirectory($dirname);
  113.  
  114.     $dirname $this->generateTmpDir();
  115.     $instance = new VersionControl_Git($dirname);
  116.     $instance->initialRepository(true);
  117.     $this->assertTrue(is_file($dirname.DIRECTORY_SEPARATOR.'HEAD'));
  118.     $this->removeDirectory($dirname);
  119.   }
  120.  
  121.   public function testGetBranches()
  122.   {
  123.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  124.  
  125.     $branches $instance->getBranches();
  126.     $this->assertEquals(count($branches)8);
  127.     $this->assertEquals($branches[0]'branch1');
  128.     $this->assertEquals($branches[7]'master');
  129.   }
  130.  
  131.   public function testGetRemoteBranches()
  132.   {
  133.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  134.  
  135.     $branches $instance->getRemoteBranches();
  136.  
  137.     $this->assertEquals(count($branches)8);
  138.     $this->assertEquals($branches[0]'branch1');
  139.     $this->assertEquals($branches[7]'master');
  140.  
  141.     $this->assertEquals(count($instance->getRemoteBranches('undefined-repository'))0);
  142.   }
  143.  
  144.   public function testGetCurrentBranch()
  145.   {
  146.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  147.  
  148.     $this->assertEquals($instance->getCurrentBranch()'master');
  149.  
  150.     $instance->checkout('branch1');
  151.     $this->assertEquals($instance->getCurrentBranch()'branch1');
  152.  
  153.     $instance->checkout('master');
  154.   }
  155.  
  156.   public function testGetHeadCommits()
  157.   {
  158.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  159.     $heads $instance->getHeadCommits();
  160.  
  161.     $this->assertEquals($heads['master']'4ed54abb8efca38a0c794ca414b1f296279e0d85');
  162.     $this->assertEquals($heads['branch1']'373efdec06a5847fd279d8c442dbfdd5df41e783');
  163.   }
  164.  
  165.   public function testGetTags()
  166.   {
  167.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  168.     $tags $instance->getTags();
  169.  
  170.     $this->assertEquals($tags['tag1']'ddf8aa7e97a206847658c90a26fe740b2e17231a');
  171.   }
  172.  
  173.   public function testGetTree()
  174.   {
  175.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  176.     $tree $instance->getTree('master')->fetch();
  177.  
  178.     $this->assertTrue($tree instanceof VersionControl_Git_Object_Tree);
  179.     $this->assertTrue($tree->current(instanceof VersionControl_Git_Object_Blob);
  180.   }
  181.  
  182.   public function testGetDirectory()
  183.   {
  184.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  185.     $this->assertEquals($instance->getDirectory()'./fixtures/001_VersionControl_Git');
  186.   }
  187.  
  188.   public function testGetGitCommandPath()
  189.   {
  190.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  191.     $this->assertEquals($instance->getGitCommandPath()'/usr/bin/git');
  192.   }
  193.  
  194.   public function testSetGitCommandPath()
  195.   {
  196.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  197.     $this->assertEquals($instance->getGitCommandPath()'/usr/bin/git');
  198.     $instance->setGitCommandPath('/usr/local/bin/git');
  199.     $this->assertEquals($instance->getGitCommandPath()'/usr/local/bin/git');
  200.   }
  201.  
  202.   protected function generateTmpDir()
  203.   {
  204.     $dirname sys_get_temp_dir().DIRECTORY_SEPARATOR.'VCG_test_'.time();
  205.     mkdir($dirname);
  206.  
  207.     return $dirname;
  208.   }
  209.  
  210.   protected function removeDirectory($dir)
  211.   {
  212.     system('rm -rf '.$dir);
  213.   }
  214. }

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