Commit 97bfaf4b authored by Thomas Löffler's avatar Thomas Löffler

Merge branch 'mutation/improve-tests-for-LTSVersionService' into 'develop'

[TEST] Improve tests for LTSVersionServer

See merge request !609
parents 6e9e1334 ff9452fc
Pipeline #10453 passed with stages
in 14 minutes and 22 seconds
......@@ -119,7 +119,7 @@ class LTSVersionService
$allLTSVersions = [];
foreach ($this->releases as $release) {
$firstReleaseOfMainVersion = $this->getFirstReleaseOfMainVersion($release['latest']);
$mainVersion = (int)($firstReleaseOfMainVersion / self::FACTOR_MAIN_VERSION);
$mainVersion = $firstReleaseOfMainVersion / self::FACTOR_MAIN_VERSION;
if ($mainVersion >= self::FIRST_LTS_VERSION_WITH_MAIN_VERSION_NUMBER || in_array($firstReleaseOfMainVersion, $this->ltsVersionsWithMinorVersions, true)) {
if ($firstReleaseOfMainVersion < VersionNumberUtility::convertVersionNumberToInteger($this->coreData['latest_lts'])) {
$allLTSVersions[] = $firstReleaseOfMainVersion;
......@@ -180,7 +180,7 @@ class LTSVersionService
*/
public function getAllLTSVersions($fullVersionNumber = true): array
{
$result = $this->getLTSVersions(true);
$result = $this->getLTSVersions();
if (!$fullVersionNumber) {
$this->convertVersionsToLabels($result);
}
......@@ -240,7 +240,7 @@ class LTSVersionService
public function getVersionLabelOfRelease(int $release): string
{
if ($release >= (self::FIRST_LTS_VERSION_WITH_MAIN_VERSION_NUMBER * self::FACTOR_MAIN_VERSION)) {
$versionLabel = (string)floor($release / self::FACTOR_MAIN_VERSION);
$versionLabel = floor($release / self::FACTOR_MAIN_VERSION);
} else {
$fullVersionLabelParts = explode('.', VersionUtility::convertIntegerToVersionNumber($release));
$versionLabel = $fullVersionLabelParts[0] . '.' . $fullVersionLabelParts[1];
......@@ -280,8 +280,8 @@ class LTSVersionService
public function isVersionLTS(int $versionNumber): bool
{
$firstRelease = (int)($versionNumber / self::FACTOR_MINOR_VERSION) * self::FACTOR_MINOR_VERSION;
$mainVersion = (int)($firstRelease / self::FACTOR_MAIN_VERSION);
$firstRelease = $this->getFirstReleaseOfMainVersion($versionNumber);
$mainVersion = $firstRelease / self::FACTOR_MAIN_VERSION;
return ($mainVersion >= self::FIRST_LTS_VERSION_WITH_MAIN_VERSION_NUMBER && $mainVersion <= $this->getLatestDevelopmentVersion()) || in_array($firstRelease, $this->ltsVersionsWithMinorVersions, true);
}
......
<?php
namespace T3o\TerFe2\Tests\Service;
/*
......@@ -62,7 +63,7 @@ class LTSVersionServiceTest extends UnitTestCase
*/
public function getAllMaintainedVersions()
{
self::assertSame(['8', '9', '10'], $this->subject->getAllMaintainedVersions());
self::assertSame(['4.7', '8', '9', '10'], $this->subject->getAllMaintainedVersions());
}
/**
......@@ -70,7 +71,7 @@ class LTSVersionServiceTest extends UnitTestCase
*/
public function getAllMaintainedVersionsAsFullVersionNumber()
{
self::assertSame([8007000, 9005000, 10000000], $this->subject->getAllMaintainedVersions(true));
self::assertSame([4007000, 8007000, 9005000, 10000000], $this->subject->getAllMaintainedVersions(true));
}
/**
......@@ -94,7 +95,7 @@ class LTSVersionServiceTest extends UnitTestCase
*/
public function getLatestDevelopmentVersionAsFullVersionNumber()
{
self::assertSame(10000000, $this->subject->getLatestDevelopmentVersion(true));
self::assertSame(10999000, $this->subject->getLatestDevelopmentVersion(true));
}
/**
......@@ -112,6 +113,17 @@ class LTSVersionServiceTest extends UnitTestCase
],
$this->subject->getAllLTSVersions()
);
self::assertSame(
[
'4.5',
'6.2',
'7',
'8',
'9'
],
$this->subject->getAllLTSVersions(false)
);
}
/**
......@@ -129,19 +141,54 @@ class LTSVersionServiceTest extends UnitTestCase
/**
* @test
* @dataProvider getActiveVersionsDataProvider
*/
public function getActiveVersions()
public function getActiveVersions($ltsOnly, $expected)
{
if (null === $ltsOnly) {
$actual = $this->subject->getActiveVersions();
} else {
$actual = $this->subject->getActiveVersions($ltsOnly);
}
self::assertSame(
[
8007000,
9005000,
10000000,
],
$this->subject->getActiveVersions()
$expected,
$actual
);
}
public function getActiveVersionsDataProvider(): array
{
return [
'ltsOnly not set, defaults to false' => [
'ltsOnly' => null,
'expected' => [
4007000,
8007000,
9005000,
10000000,
],
],
'ltsOnly set to false' => [
'ltsOnly' => false,
'expected' => [
4007000,
8007000,
9005000,
10000000,
],
],
'ltsOnly set to true' => [
'ltsOnly' => true,
'expected' => [
8007000,
9005000,
10000000,
],
],
];
}
/**
* @test
*/
......@@ -181,12 +228,25 @@ class LTSVersionServiceTest extends UnitTestCase
/**
* @test
*/
public function getVersionLabelOfNewVersion()
public function getVersionLabelOfRelease()
{
self::assertSame(
'8',
$this->subject->getVersionLabelOfRelease(8007004)
);
self::assertSame(
'7',
$this->subject->getVersionLabelOfRelease(7000000)
);
// Ensures the floor() is tested
self::assertSame(
'7',
$this->subject->getVersionLabelOfRelease(7999000)
);
self::assertIsString($this->subject->getVersionLabelOfRelease(8007004));
}
/**
......@@ -265,7 +325,9 @@ class LTSVersionServiceTest extends UnitTestCase
],
'4.7' => [
'latest' => '4.7.40',
'active' => false,
// Has to be active otherwise the getActiveVersions will not have
// a test case for active not LTS.
'active' => true,
'elts' => false,
],
'4.6' => [
......@@ -278,7 +340,10 @@ class LTSVersionServiceTest extends UnitTestCase
'active' => false,
'elts' => false,
],
'latest_stable' => '10.0.0',
// Needs to have 10.999.0 or higher to have the getLatestDevelopmentVersion() floor()
// part tested, otherwise a ceil() would give the same result and return in an error,
// when getting to higher version numbers.
'latest_stable' => '10.999.0',
'latest_old_stable' => '9.5.5',
'latest_lts' => '9.5.5',
'latest_old_lts' => '8.7.9'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment