/** * @covers ::calculate * @covers ::calculatePartDifference * @dataProvider providePreReleaseParts */ public function testCanComparePreReleases($a, $b, $expectedResult) { // ---------------------------------------------------------------- // setup your test // ---------------------------------------------------------------- // perform the change $actualResult = CompareTwoPreReleaseParts::calculate($a, $b); // ---------------------------------------------------------------- // test the results $this->assertEquals($expectedResult, $actualResult); }
/** * compare the segments of the <pre-release> section * * @param array $aParts * the <pre-release> part of LHS, split by '.' * @param array $bParts * the <pre-release> part of RHS, split by '.' * @return int */ private static function comparePreReleaseParts($aParts, $bParts) { // step-by-step comparison foreach ($aParts as $i => $aPart) { // if we've run out of parts, $a wins if (!isset($bParts[$i])) { return CompareTwoNumbers::A_IS_GREATER; } // shorthand $bPart = $bParts[$i]; // what can we learn about them? $res = CompareTwoPreReleaseParts::calculate($aPart, $bPart); if ($res !== CompareTwoNumbers::BOTH_ARE_EQUAL) { return $res; } } return CompareTwoNumbers::BOTH_ARE_EQUAL; }