Source for file VersionControl_GitTest.php
Documentation is available at VersionControl_GitTest.php
require_once 'PHPUnit/Autoload.php';
require_once 'VersionControl/Git.php';
require_once './checkFixtures.php';
class VersionControl_GitTest extends PHPUnit_Framework_TestCase
public function testConstructException ()
$this->setExpectedException ('VersionControl_Git_Exception');
public function testConstruct ()
public function testGetGitVersion ()
$version = $instance->getGitVersion ();
$this->assertTrue ((bool) preg_match('/^[0-9]+\.[0-9]+\.[0-9]+/', $version));
public function testGetCommits ()
$commits = $instance->getCommits ();
$this->assertEquals (count($commits), 100 );
$commits = $instance->getCommits ('master', 5 );
$this->assertEquals (count($commits), 5 );
$commits = $instance->getCommits ('master', 1 );
$this->assertEquals ($commits[0 ]->id , '4ed54abb8efca38a0c794ca414b1f296279e0d85');
$commits = $instance->getCommits ('branch1', 1 );
$this->assertEquals ($commits[0 ]->id , '373efdec06a5847fd279d8c442dbfdd5df41e783');
$commits = $instance->getCommits ('master', 1 , 10 );
$this->assertEquals ($commits[0 ]->id , 'bf3488d82c09a749cefbb2633f9605b6ab5cf71e');
public function testCreateClone ()
$dirname = $this->generateTmpDir ();
$instance->createClone ('git://gist.github.com/265855.git');
$this->assertTrue (is_dir($dirname.DIRECTORY_SEPARATOR. '265855'));
$this->removeDirectory ($dirname);
$dirname = $this->generateTmpDir ();
$instance->createClone ('git://gist.github.com/265855.git', true );
// see: http://git.kernel.org/?p=git/git.git;a=commit;h=6612f87
$this->assertTrue (is_file($dirname.DIRECTORY_SEPARATOR. '265855'.DIRECTORY_SEPARATOR. 'HEAD'));
$this->assertTrue (is_file($dirname.DIRECTORY_SEPARATOR. '265855.git'.DIRECTORY_SEPARATOR. 'HEAD'));
$this->removeDirectory ($dirname);
$dirname = $this->generateTmpDir ();
$instance->createClone ('git://gist.github.com/265855.git', true , $dirname.DIRECTORY_SEPARATOR. 'MY_WORKING_COPY');
$this->assertTrue (is_dir($dirname.DIRECTORY_SEPARATOR. 'MY_WORKING_COPY'));
$this->assertTrue (realpath($instance->getDirectory ()) === realpath($dirname.DIRECTORY_SEPARATOR. 'MY_WORKING_COPY'));
$this->removeDirectory ($dirname);
$dirname = $this->generateTmpDir ();
$instance->createClone ('git://gist.github.com/265855.git', false , $dirname);
$this->assertTrue (is_file($dirname.DIRECTORY_SEPARATOR. 'patch_for_pecl_runkit.diff'));
$this->removeDirectory ($dirname);
public function testInitRepository ()
$dirname = $this->generateTmpDir ();
$instance->initRepository ();
$this->assertTrue (is_dir($dirname.DIRECTORY_SEPARATOR. '.git'));
$this->removeDirectory ($dirname);
$dirname = $this->generateTmpDir ();
$instance->initRepository (true );
$this->assertTrue (is_file($dirname.DIRECTORY_SEPARATOR. 'HEAD'));
$this->removeDirectory ($dirname);
public function testInitialRepository ()
$dirname = $this->generateTmpDir ();
$instance->initialRepository ();
$this->assertTrue (is_dir($dirname.DIRECTORY_SEPARATOR. '.git'));
$this->removeDirectory ($dirname);
$dirname = $this->generateTmpDir ();
$instance->initialRepository (true );
$this->assertTrue (is_file($dirname.DIRECTORY_SEPARATOR. 'HEAD'));
$this->removeDirectory ($dirname);
public function testGetBranches ()
$branches = $instance->getBranches ();
$this->assertEquals (count($branches), 8 );
$this->assertEquals ($branches[0 ], 'branch1');
$this->assertEquals ($branches[7 ], 'master');
public function testGetRemoteBranches ()
$branches = $instance->getRemoteBranches ();
$this->assertEquals (count($branches), 8 );
$this->assertEquals ($branches[0 ], 'branch1');
$this->assertEquals ($branches[7 ], 'master');
$this->assertEquals (count($instance->getRemoteBranches ('undefined-repository')), 0 );
public function testGetCurrentBranch ()
$this->assertEquals ($instance->getCurrentBranch (), 'master');
$instance->checkout ('branch1');
$this->assertEquals ($instance->getCurrentBranch (), 'branch1');
$instance->checkout ('master');
public function testGetHeadCommits ()
$heads = $instance->getHeadCommits ();
$this->assertEquals ($heads['master'], '4ed54abb8efca38a0c794ca414b1f296279e0d85');
$this->assertEquals ($heads['branch1'], '373efdec06a5847fd279d8c442dbfdd5df41e783');
public function testGetTags ()
$tags = $instance->getTags ();
$this->assertEquals ($tags['tag1'], 'ddf8aa7e97a206847658c90a26fe740b2e17231a');
public function testGetTree ()
$tree = $instance->getTree ('master')->fetch ();
public function testGetDirectory ()
$this->assertEquals ($instance->getDirectory (), './fixtures/001_VersionControl_Git');
public function testGetGitCommandPath ()
$this->assertEquals ($instance->getGitCommandPath (), '/usr/bin/git');
public function testSetGitCommandPath ()
$this->assertEquals ($instance->getGitCommandPath (), '/usr/bin/git');
$instance->setGitCommandPath ('/usr/local/bin/git');
$this->assertEquals ($instance->getGitCommandPath (), '/usr/local/bin/git');
protected function generateTmpDir ()
protected function removeDirectory ($dir)
Documentation generated on Mon, 11 Mar 2019 15:43:05 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|