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/Framework.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 testGetCommits()
  27.   {
  28.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  29.     $commits $instance->getCommits();
  30.  
  31.     $this->assertTrue($commits[0instanceof VersionControl_Git_Object_Commit);
  32.     $this->assertEquals(count($commits)100);
  33.  
  34.     $commits $instance->getCommits('master'5);
  35.     $this->assertEquals(count($commits)5);
  36.  
  37.     $commits $instance->getCommits('master'1);
  38.     $this->assertEquals($commits[0]->id'4ed54abb8efca38a0c794ca414b1f296279e0d85');
  39.  
  40.     $commits $instance->getCommits('branch1'1);
  41.     $this->assertEquals($commits[0]->id'373efdec06a5847fd279d8c442dbfdd5df41e783');
  42.  
  43.     $commits $instance->getCommits('master'110);
  44.     $this->assertEquals($commits[0]->id'bf3488d82c09a749cefbb2633f9605b6ab5cf71e');
  45.   }
  46.  
  47.   public function testCreateClone()
  48.   {
  49.     $dirname $this->generateTmpDir();
  50.     $instance = new VersionControl_Git($dirname);
  51.     $instance->createClone('git://gist.github.com/265855.git');
  52.     $this->assertTrue(is_dir($dirname.DIRECTORY_SEPARATOR.'265855'));
  53.     $this->removeDirectory($dirname);
  54.  
  55.     $dirname $this->generateTmpDir();
  56.     $instance = new VersionControl_Git($dirname);
  57.     $instance->createClone('git://gist.github.com/265855.git'true);
  58.     $this->assertTrue(is_file($dirname.DIRECTORY_SEPARATOR.'265855.git'.DIRECTORY_SEPARATOR.'HEAD'));
  59.     $this->removeDirectory($dirname);
  60.  
  61.     $dirname $this->generateTmpDir();
  62.     $instance = new VersionControl_Git($dirname);
  63.     $instance->createClone('git://gist.github.com/265855.git'true$dirname.DIRECTORY_SEPARATOR.'MY_WORKING_COPY');
  64.     $this->assertTrue(is_dir($dirname.DIRECTORY_SEPARATOR.'MY_WORKING_COPY'));
  65.     $this->assertTrue(realpath($instance->getDirectory()) === realpath($dirname.DIRECTORY_SEPARATOR.'MY_WORKING_COPY'));
  66.     $this->removeDirectory($dirname);
  67.   }
  68.  
  69.   public function testInitRepository()
  70.   {
  71.     $dirname $this->generateTmpDir();
  72.     $instance = new VersionControl_Git($dirname);
  73.     $instance->initRepository();
  74.     $this->assertTrue(is_dir($dirname.DIRECTORY_SEPARATOR.'.git'));
  75.     $this->removeDirectory($dirname);
  76.  
  77.     $dirname $this->generateTmpDir();
  78.     $instance = new VersionControl_Git($dirname);
  79.     $instance->initRepository(true);
  80.     $this->assertTrue(is_file($dirname.DIRECTORY_SEPARATOR.'HEAD'));
  81.     $this->removeDirectory($dirname);
  82.   }
  83.  
  84.   public function testInitialRepository()
  85.   {
  86.     $dirname $this->generateTmpDir();
  87.     $instance = new VersionControl_Git($dirname);
  88.     $instance->initialRepository();
  89.     $this->assertTrue(is_dir($dirname.DIRECTORY_SEPARATOR.'.git'));
  90.     $this->removeDirectory($dirname);
  91.  
  92.     $dirname $this->generateTmpDir();
  93.     $instance = new VersionControl_Git($dirname);
  94.     $instance->initialRepository(true);
  95.     $this->assertTrue(is_file($dirname.DIRECTORY_SEPARATOR.'HEAD'));
  96.     $this->removeDirectory($dirname);
  97.   }
  98.  
  99.   public function testGetBranches()
  100.   {
  101.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  102.  
  103.     $branches $instance->getBranches();
  104.     $this->assertEquals(count($branches)8);
  105.     $this->assertEquals($branches[0]'branch1');
  106.     $this->assertEquals($branches[7]'master');
  107.   }
  108.  
  109.   public function testGetCurrentBranch()
  110.   {
  111.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  112.  
  113.     $this->assertEquals($instance->getCurrentBranch()'master');
  114.  
  115.     $instance->checkout('branch1');
  116.     $this->assertEquals($instance->getCurrentBranch()'branch1');
  117.  
  118.     $instance->checkout('master');
  119.   }
  120.  
  121.   public function testGetHeadCommits()
  122.   {
  123.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  124.     $heads $instance->getHeadCommits();
  125.  
  126.     $this->assertEquals($heads['master']'4ed54abb8efca38a0c794ca414b1f296279e0d85');
  127.     $this->assertEquals($heads['branch1']'373efdec06a5847fd279d8c442dbfdd5df41e783');
  128.   }
  129.  
  130.   public function testGetTags()
  131.   {
  132.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  133.     $tags $instance->getTags();
  134.  
  135.     $this->assertEquals($tags['tag1']'ddf8aa7e97a206847658c90a26fe740b2e17231a');
  136.   }
  137.  
  138.   public function testGetTree()
  139.   {
  140.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  141.     $tree $instance->getTree('master')->fetch();
  142.  
  143.     $this->assertTrue($tree instanceof VersionControl_Git_Object_Tree);
  144.     $this->assertTrue($tree->current(instanceof VersionControl_Git_Object_Blob);
  145.   }
  146.  
  147.   public function testGetDirectory()
  148.   {
  149.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  150.     $this->assertEquals($instance->getDirectory()'./fixtures/001_VersionControl_Git');
  151.   }
  152.  
  153.   public function testGetGitCommandPath()
  154.   {
  155.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  156.     $this->assertEquals($instance->getGitCommandPath()'/usr/bin/git');
  157.   }
  158.  
  159.   public function testSetGitCommandPath()
  160.   {
  161.     $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
  162.     $this->assertEquals($instance->getGitCommandPath()'/usr/bin/git');
  163.     $instance->setGitCommandPath('/usr/local/bin/git');
  164.     $this->assertEquals($instance->getGitCommandPath()'/usr/local/bin/git');
  165.   }
  166.  
  167.   protected function generateTmpDir()
  168.   {
  169.     $dirname sys_get_temp_dir().DIRECTORY_SEPARATOR.'VCG_test_'.time();
  170.     mkdir($dirname);
  171.  
  172.     return $dirname;
  173.   }
  174.  
  175.   protected function removeDirectory($dir)
  176.   {
  177.     foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)RecursiveIteratorIterator::CHILD_FIRSTas $file)
  178.     {
  179.       if ($file->isDir())
  180.       {
  181.         rmdir($file->getPathname());
  182.       }
  183.       else
  184.       {
  185.         unlink($file->getPathname());
  186.       }
  187.     }
  188.  
  189.     rmdir($dir);
  190.   }
  191. }

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