Skip to content

Commit

Permalink
[FEATURE] Exclude release candidate versions from platform versions
Browse files Browse the repository at this point in the history
  • Loading branch information
cngJo committed Jan 23, 2024
1 parent 2fb93d8 commit 5ed46d8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Service/PlatformDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final class PlatformDataProvider
public function __construct(
private readonly InstanceService $instanceService,
private readonly HttpClientInterface $client,
private readonly VersionFilterService $versionFilterService
) {
}

Expand All @@ -29,6 +30,8 @@ public function getLatestPlatformVersion(): string
return version_compare($b, $a);
});

$versions = $this->versionFilterService->removeReleaseCandidates($versions);

return $versions[0];
}
}
26 changes: 26 additions & 0 deletions src/Service/VersionFilterService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace MobilisticsGmbH\MamoConnector\Service;

class VersionFilterService
{
/**
* Remove all release candidates from the given array of versions.
*
* Note: this currently does not do proper semver parsing, and only checks for the string 'rc' in the version.
*
* @param array<string> $versions
* @return array<string>
*/
public function removeReleaseCandidates(array $versions): array
{
return array_values(
array_filter(
$versions,
static fn ($version) => ! str_contains(strtolower($version), 'rc')
)
);
}
}
32 changes: 32 additions & 0 deletions tests/Service/VersionFilterServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace MobilisticsGmbH\MamoConnector\Tests\Service;

use MobilisticsGmbH\MamoConnector\Service\VersionFilterService;
use PHPUnit\Framework\TestCase;

class VersionFilterServiceTest extends TestCase
{
public function testRemoveRCDoesNotChangeWhenNoRCVersions(): void
{
$versions = ['6.4.20.2', '6.5.8.2'];

$filteredVersions = $this->getFilterVersionService()->removeReleaseCandidates($versions);
static::assertSame($versions, $filteredVersions);
}

public function testRemoveRCRemovesRCVersions(): void
{
$versions = ['6.4.20.2', '6.5.8.2', '6.6.0.0-rc1'];

$filteredVersions = $this->getFilterVersionService()->removeReleaseCandidates($versions);
static::assertSame(['6.4.20.2', '6.5.8.2'], $filteredVersions);
}

private function getFilterVersionService(): VersionFilterService
{
return new VersionFilterService();
}
}

0 comments on commit 5ed46d8

Please sign in to comment.