Skip to content

Commit cb3c87a

Browse files
committed
minor #4671 TravisTest - rewrite tests to allow last supported by tool PHP version to be snapshot (keradus)
This PR was merged into the 2.15 branch. Discussion ---------- TravisTest - rewrite tests to allow last supported by tool PHP version to be snapshot Commits ------- 5705844 TravisTest - rewrite tests to allow last supported by tool PHP version to be snapshot
2 parents d62f301 + 5705844 commit cb3c87a

File tree

1 file changed

+77
-29
lines changed

1 file changed

+77
-29
lines changed

tests/AutoReview/TravisTest.php

Lines changed: 77 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,58 +31,106 @@ final class TravisTest extends TestCase
3131
{
3232
public function testTestJobsRunOnEachPhp()
3333
{
34-
$expectedVersions = [];
35-
$expectedMinPhp = (float) $this->getMinPhpVersionFromEntryFile();
36-
$expectedMaxPhp = (float) $this->getMaxPhpVersionFromEntryFile();
34+
$supportedVersions = [];
35+
$supportedMinPhp = (float) $this->getMinPhpVersionFromEntryFile();
36+
$supportedMaxPhp = (float) $this->getMaxPhpVersionFromEntryFile();
3737

38-
if ($expectedMinPhp < 7) {
39-
$expectedMinPhp = 7;
40-
$expectedVersions[] = '5.6';
38+
if ($supportedMinPhp < 7) {
39+
$supportedMinPhp = 7;
40+
$supportedVersions[] = '5.6';
4141
}
4242

43-
for ($version = $expectedMinPhp; $version <= $expectedMaxPhp; $version += 0.1) {
44-
$expectedVersions[] = sprintf('%.1f', $version);
43+
for ($version = $supportedMinPhp; $version <= $supportedMaxPhp; $version += 0.1) {
44+
$supportedVersions[] = sprintf('%.1f', $version);
4545
}
4646

47-
$jobs = array_filter($this->getTravisJobs(), function ($job) {
48-
return false !== strpos($job['stage'], 'Test');
49-
});
50-
static::assertGreaterThanOrEqual(1, \count($jobs));
47+
$ciVersions = $this->getAllPhpVersionsUsedByCiForTests();
5148

52-
$versions = array_map(function ($job) {
53-
return $job['php'];
54-
}, $jobs);
49+
static::assertGreaterThanOrEqual(1, \count($ciVersions));
50+
51+
self::assertSupportedPhpVersionsAreCoveredByCiJobs($supportedVersions, $ciVersions);
52+
self::assertUpcomingPhpVersionIsCoveredByCiJob(end($supportedVersions), $ciVersions);
53+
}
54+
55+
public function testDeploymentJobsRunOnLatestStablePhpThatIsSupportedByTool()
56+
{
57+
$ciVersionsForDeployments = $this->getAllPhpVersionsUsedByCiForDeployments();
58+
$ciVersions = $this->getAllPhpVersionsUsedByCiForTests();
59+
$expectedPhp = $this->getMaxPhpVersionFromEntryFile();
60+
61+
if (\in_array($expectedPhp.'snapshot', $ciVersions, true)) {
62+
// last version of used PHP is snapshot. we should test against previous one, that is stable
63+
$expectedPhp = (string) ((float) $expectedPhp - 0.1);
64+
}
65+
66+
static::assertGreaterThanOrEqual(1, \count($ciVersionsForDeployments));
67+
static::assertGreaterThanOrEqual(1, \count($ciVersions));
5568

56-
foreach ($expectedVersions as $expectedVersion) {
57-
static::assertContains($expectedVersion, $versions);
69+
foreach ($ciVersionsForDeployments as $ciVersionsForDeployment) {
70+
static::assertTrue(
71+
version_compare($expectedPhp, $ciVersionsForDeployment, 'eq'),
72+
sprintf('Expects %s to be %s', $ciVersionsForDeployment, $expectedPhp)
73+
);
5874
}
75+
}
5976

77+
private static function assertUpcomingPhpVersionIsCoveredByCiJob($lastSupportedVersion, array $ciVersions)
78+
{
6079
if (!class_exists(TraversableContains::class)) {
6180
static::markTestSkipped('TraversableContains not available.');
6281
}
6382

64-
static::assertThat($versions, static::logicalOr(
83+
static::assertThat($ciVersions, static::logicalOr(
84+
// if `$lastsupportedVersion` is already a snapshot version
85+
new TraversableContains(sprintf('%.1fsnapshot', $lastSupportedVersion)),
86+
// if `$lastsupportedVersion` is not snapshot version, expect CI to run snapshot of next PHP version
6587
new TraversableContains('nightly'),
66-
new TraversableContains(sprintf('%.1fsnapshot', end($expectedVersions) + 0.1))
88+
new TraversableContains(sprintf('%.1fsnapshot', $lastSupportedVersion + 0.1))
89+
));
90+
}
91+
92+
private static function assertSupportedPhpVersionsAreCoveredByCiJobs(array $supportedVersions, array $ciVersions)
93+
{
94+
$lastSupportedVersion = array_pop($supportedVersions);
95+
96+
foreach ($supportedVersions as $expectedVersion) {
97+
static::assertContains($expectedVersion, $ciVersions);
98+
}
99+
100+
if (!class_exists(TraversableContains::class)) {
101+
static::markTestSkipped('TraversableContains not available.');
102+
}
103+
104+
static::assertThat($ciVersions, static::logicalOr(
105+
new TraversableContains($lastSupportedVersion),
106+
new TraversableContains(sprintf('%.1fsnapshot', $lastSupportedVersion))
67107
));
68108
}
69109

70-
public function testDeploymentJobsRunOnLatestPhp()
110+
private function getAllPhpVersionsUsedByCiForDeployments()
71111
{
72112
$jobs = array_filter($this->getTravisJobs(), function ($job) {
73113
return 'Deployment' === $job['stage'];
74114
});
75-
static::assertGreaterThanOrEqual(1, \count($jobs));
76115

77-
$expectedPhp = $this->getMaxPhpVersionFromEntryFile();
116+
$versions = array_map(function ($job) {
117+
return (string) $job['php'];
118+
}, $jobs);
78119

79-
foreach ($jobs as $job) {
80-
$jobPhp = (string) $job['php'];
81-
static::assertTrue(
82-
version_compare($expectedPhp, $jobPhp, 'eq'),
83-
sprintf('Expects %s to be %s', $jobPhp, $expectedPhp)
84-
);
85-
}
120+
return $versions;
121+
}
122+
123+
private function getAllPhpVersionsUsedByCiForTests()
124+
{
125+
$jobs = array_filter($this->getTravisJobs(), function ($job) {
126+
return false !== strpos($job['stage'], 'Test');
127+
});
128+
129+
$versions = array_map(function ($job) {
130+
return (string) $job['php'];
131+
}, $jobs);
132+
133+
return $versions;
86134
}
87135

88136
private function convertPhpVerIdToNiceVer($verId)

0 commit comments

Comments
 (0)