/** * Compares two commits by age * * @param GitPHP_Commit $a first commit * @param GitPHP_Commit $b second commit * @return integer comparison result */ public static function CompareAge($a, $b) { if ($a->GetAge() === $b->GetAge()) { // fall back on author epoch return 0 - GitPHP_Commit::CompareAuthorEpoch($a, $b); } return $a->GetAge() < $b->GetAge() ? -1 : 1; }
public function testCompareAuthorEpoch() { $commitdata = array(null, null, array(), null, '12345678', null, null, null, 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, null, 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::CompareAuthorEpoch($commit, $commit2)); $this->assertGreaterThan(0, GitPHP_Commit::CompareAuthorEpoch($commit2, $commit)); $commitdata = array(null, null, array(), null, '12345678', null, null, null, 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, null, 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->assertEquals(0, GitPHP_Commit::CompareAuthorEpoch($commit, $commit2)); $this->assertEquals(0, GitPHP_Commit::CompareAuthorEpoch($commit2, $commit)); }