/** * CompareAge * * Compares two tags by age * * @access public * @static * @param mixed $a first tag * @param mixed $b second tag * @return integer comparison result */ public static function CompareAge($a, $b) { $aObj = $a->GetObject(); $bObj = $b->GetObject(); if ($aObj instanceof GitPHP_Commit && $bObj instanceof GitPHP_Commit) { return GitPHP_Commit::CompareAge($aObj, $bObj); } if ($aObj instanceof GitPHP_Commit) { return 1; } if ($bObj instanceof GitPHP_Commit) { return -1; } return strcmp($a->GetName(), $b->GetName()); }
/** * CompareAge * * Compares two heads by age * * @access public * @static * @param mixed $a first head * @param mixed $b second head * @return integer comparison result */ public static function CompareAge($a, $b) { $aObj = $a->GetCommit(); $bObj = $b->GetCommit(); return GitPHP_Commit::CompareAge($aObj, $bObj); }
public function testCompareAge() { $commitdata = array(null, null, array(), null, '12345678', null, null, '2', null, null, array()); $loadstrategy = $this->getMock('GitPHP_CommitLoadStrategy_Interface'); $loadstrategy->expects($this->once())->method('Load')->with($this->isInstanceOf('GitPHP_Commit'))->will($this->returnValue($commitdata)); $commit = new GitPHP_Commit($this->getMockBuilder('GitPHP_Project')->disableOriginalConstructor()->getMock(), '1234567890abcdef1234567890ABCDEF12345678', $loadstrategy); $commitdata2 = array(null, null, array(), null, '12345678', null, null, '1', null, null, array()); $loadstrategy2 = $this->getMock('GitPHP_CommitLoadStrategy_Interface'); $loadstrategy2->expects($this->once())->method('Load')->with($this->isInstanceOf('GitPHP_Commit'))->will($this->returnValue($commitdata2)); $commit2 = new GitPHP_Commit($this->getMockBuilder('GitPHP_Project')->disableOriginalConstructor()->getMock(), '1234567890abcdef1234567890ABCDEF12345678', $loadstrategy2); $this->assertLessThan(0, GitPHP_Commit::CompareAge($commit, $commit2)); $this->assertGreaterThan(0, GitPHP_Commit::CompareAge($commit2, $commit)); $commitdata = array(null, null, array(), null, '12345678', null, null, '1', null, null, array()); $loadstrategy = $this->getMock('GitPHP_CommitLoadStrategy_Interface'); $loadstrategy->expects($this->once())->method('Load')->with($this->isInstanceOf('GitPHP_Commit'))->will($this->returnValue($commitdata)); $commit = new GitPHP_Commit($this->getMockBuilder('GitPHP_Project')->disableOriginalConstructor()->getMock(), '1234567890abcdef1234567890ABCDEF12345678', $loadstrategy); $commitdata2 = array(null, null, array(), null, '12345679', null, null, '1', null, null, array()); $loadstrategy2 = $this->getMock('GitPHP_CommitLoadStrategy_Interface'); $loadstrategy2->expects($this->once())->method('Load')->with($this->isInstanceOf('GitPHP_Commit'))->will($this->returnValue($commitdata2)); $commit2 = new GitPHP_Commit($this->getMockBuilder('GitPHP_Project')->disableOriginalConstructor()->getMock(), '1234567890abcdef1234567890ABCDEF12345678', $loadstrategy2); $this->assertGreaterThan(0, GitPHP_Commit::CompareAge($commit, $commit2)); $this->assertLessThan(0, GitPHP_Commit::CompareAge($commit2, $commit)); }