Skip to content

Commit 65a4f59

Browse files
committed
minor #4264 DX: AutoReview - ensure Travis handle all needed PHP versions (keradus)
This PR was squashed before being merged into the 2.12 branch (closes #4264). Discussion ---------- DX: AutoReview - ensure Travis handle all needed PHP versions Commits ------- a1d7595 DX: AutoReview - ensure Travis handle all needed PHP versions
2 parents 120dfe2 + a1d7595 commit 65a4f59

File tree

3 files changed

+145
-4
lines changed

3 files changed

+145
-4
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ jobs:
145145

146146
-
147147
stage: Deployment
148-
php: 7.1
148+
php: 7.3
149149
install: ./dev-tools/build.sh
150150
script:
151151
- PHP_CS_FIXER_TEST_ALLOW_SKIPPING_SMOKE_TESTS=0 vendor/bin/phpunit tests/Smoke/

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@
4040
"php-cs-fixer/accessible-object": "^1.0",
4141
"php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.1",
4242
"php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.1",
43-
"phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1",
44-
"phpunitgoodpractices/traits": "^1.8",
45-
"symfony/phpunit-bridge": "^4.3"
43+
"phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.1",
44+
"phpunitgoodpractices/traits": "^1.5.1",
45+
"symfony/phpunit-bridge": "^4.0",
46+
"symfony/yaml": "^3.0 || ^4.0"
4647
},
4748
"suggest": {
4849
"ext-mbstring": "For handling non-UTF8 characters in cache signature.",

tests/AutoReview/TravisTest.php

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<?php
2+
3+
/*
4+
* This file is part of PHP CS Fixer.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
8+
*
9+
* This source file is subject to the MIT license that is bundled
10+
* with this source code in the file LICENSE.
11+
*/
12+
13+
namespace PhpCsFixer\Tests\AutoReview;
14+
15+
use PhpCsFixer\Preg;
16+
use PhpCsFixer\Tests\TestCase;
17+
use PhpCsFixer\Tokenizer\Tokens;
18+
use PHPUnit\Framework\Constraint\TraversableContains;
19+
use Symfony\Component\Yaml\Yaml;
20+
21+
/**
22+
* @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
23+
*
24+
* @internal
25+
*
26+
* @coversNothing
27+
* @group auto-review
28+
* @group covers-nothing
29+
*/
30+
final class TravisTest extends TestCase
31+
{
32+
public function testTestJobsRunOnEachPhp()
33+
{
34+
$expectedVersions = [];
35+
$expectedMinPhp = (float) $this->getMinPhpVersionFromEntryFile();
36+
$expectedMaxPhp = (float) $this->getMaxPhpVersionFromEntryFile();
37+
38+
if ($expectedMinPhp < 7) {
39+
$expectedMinPhp = 7;
40+
$expectedVersions[] = '5.6';
41+
}
42+
43+
for ($version = $expectedMinPhp; $version <= $expectedMaxPhp; $version += 0.1) {
44+
$expectedVersions[] = sprintf('%.1f', $version);
45+
}
46+
47+
$jobs = array_filter($this->getTravisJobs(), function ($job) {
48+
return false !== strpos($job['stage'], 'Test');
49+
});
50+
static::assertGreaterThanOrEqual(1, \count($jobs));
51+
52+
$versions = array_map(function ($job) {
53+
return $job['php'];
54+
}, $jobs);
55+
56+
foreach ($expectedVersions as $expectedVersion) {
57+
static::assertContains($expectedVersion, $versions);
58+
}
59+
60+
if (!class_exists(TraversableContains::class)) {
61+
static::markTestSkipped('TraversableContains not available.');
62+
}
63+
64+
static::assertThat($versions, static::logicalOr(
65+
new TraversableContains('nightly'),
66+
new TraversableContains(sprintf('%.1fsnapshot', end($expectedVersions) + 0.1))
67+
));
68+
}
69+
70+
public function testDeploymentJobsRunOnLatestPhp()
71+
{
72+
$jobs = array_filter($this->getTravisJobs(), function ($job) {
73+
return 'Deployment' === $job['stage'];
74+
});
75+
static::assertGreaterThanOrEqual(1, \count($jobs));
76+
77+
$expectedPhp = $this->getMaxPhpVersionFromEntryFile();
78+
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+
}
86+
}
87+
88+
private function convertPhpVerIdToNiceVer($verId)
89+
{
90+
$matchResult = Preg::match('/^(?<major>\d{1,2})(?<minor>\d{2})(?<patch>\d{2})$/', $verId, $capture);
91+
if (1 !== $matchResult) {
92+
throw new \LogicException("Can't parse version id.");
93+
}
94+
95+
return sprintf('%d.%d', $capture['major'], $capture['minor']);
96+
}
97+
98+
private function getMaxPhpVersionFromEntryFile()
99+
{
100+
$tokens = Tokens::fromCode(file_get_contents(__DIR__.'/../../php-cs-fixer'));
101+
$sequence = $tokens->findSequence([
102+
[T_STRING, 'PHP_VERSION_ID'],
103+
[T_IS_GREATER_OR_EQUAL],
104+
[T_LNUMBER],
105+
]);
106+
107+
if (null === $sequence) {
108+
throw new \LogicException("Can't find version - perhaps entry file was modified?");
109+
}
110+
111+
$phpVerId = end($sequence)->getContent();
112+
113+
return $this->convertPhpVerIdToNiceVer((string) ($phpVerId - 100));
114+
}
115+
116+
private function getMinPhpVersionFromEntryFile()
117+
{
118+
$tokens = Tokens::fromCode(file_get_contents(__DIR__.'/../../php-cs-fixer'));
119+
$sequence = $tokens->findSequence([
120+
[T_STRING, 'PHP_VERSION_ID'],
121+
'<',
122+
[T_LNUMBER],
123+
]);
124+
125+
if (null === $sequence) {
126+
throw new \LogicException("Can't find version - perhaps entry file was modified?");
127+
}
128+
129+
$phpVerId = end($sequence)->getContent();
130+
131+
return $this->convertPhpVerIdToNiceVer($phpVerId);
132+
}
133+
134+
private function getTravisJobs()
135+
{
136+
$yaml = Yaml::parse(file_get_contents(__DIR__.'/../../.travis.yml'));
137+
138+
return $yaml['jobs']['include'];
139+
}
140+
}

0 commit comments

Comments
 (0)