From 84a7f70114f557029b91f6f21993ae189745d471 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 12 Sep 2024 15:00:21 +1200 Subject: [PATCH] FIX Fix logic to allow unit tests to pass --- job_creator.php | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/job_creator.php b/job_creator.php index 8e7678d..400418c 100644 --- a/job_creator.php +++ b/job_creator.php @@ -102,12 +102,8 @@ public function getInstallerVersion( return $cmsMajor . '.x-dev'; } sort($minorPortions); - $minorPortion = $minorPortions[count($minorPortions) - 1]; - $installerVersion = $cmsMajor . '.' . $minorPortion; - // It's normal for new major versions branches to exist a year or more before the first release - // The corresponding minor version branch will not exist at this time - // Check that the minor version of the installer branches exists, if not, fallback to using the major + // Get data about which branches exist so we can avoid testing against non-existent branches if ($installerBranchesJson) { // this if for unit testing $json = json_decode($installerBranchesJson); @@ -119,14 +115,23 @@ public function getInstallerVersion( $json = json_decode(file_get_contents('__installer_branches.json')); } $branches = array_column($json, 'name'); - // using array_filter() instead of in_array() to ensure we get a strict equality check - // e.g. '6' and '6.0' are not equal - $branchExists = count(array_filter($branches, fn($branch) => $branch === $installerVersion)); - if (!$branchExists) { - return $cmsMajor . '.x-dev'; + + // It's normal for new major versions branches to exist a year or more before the first release + // and also our unit tests don't get magically updated when we release new minor releases. + // The corresponding minor version branch may not exist. + // Check that the minor version of the installer branches exists, if not, fallback to using the major + foreach (array_reverse($minorPortions) as $minorPortion) { + $installerVersion = $cmsMajor . '.' . $minorPortion; + // using array_filter() instead of in_array() to ensure we get a strict equality check + // e.g. '6' and '6.0' are not equal + $branchExists = count(array_filter($branches, fn($branch) => $branch === $installerVersion)); + if ($branchExists) { + return $installerVersion . '.x-dev'; + } } - return $installerVersion . '.x-dev'; + // If there were no branches for any minor version, fall back to the next-minor branch + return $cmsMajor . '.x-dev'; } }