Browse Source

feat: SPIP/PHP compatibility matrix

merge-requests/11/merge
James 2 years ago
parent
commit
653aa4bc1a
  1. 2
      .gitlab-ci.yml
  2. 1
      CHANGELOG
  3. 1
      README.md
  4. 31
      modeles/supportedversions_compatibility.html
  5. 59
      supportedversions_fonctions.php
  6. 49
      tests/SupportedVersionsTest.php
  7. 33
      tests/releases/init.json

2
.gitlab-ci.yml

@ -19,7 +19,7 @@ lint:
test:
stage: test
script:
- vendor/bin/phpunit --colors=never
- php -d xdebug.mode=coverage vendor/bin/phpunit --colors=never
artifacts:
paths:
- .phpunit.cache

1
CHANGELOG

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- CI/CD Pipeline
- `<supportedversions|compatibility`> model
## [0.3.0] - 2020-10-12

1
README.md

@ -14,6 +14,7 @@ SPIP Plugin backport of [PHP Supported Versions](http://php.net/supported-versio
- `<supportedversions|releases>` : list of releases in JSON
- `<supportedversions|latest>`: list of the latest releases of active branches
- `<supportedversions|eol>`: list of the end of life branches
- `<supportedversions|compatibility>`: table matrix of SPIP/PHP Compatibility
## Other usage

31
modeles/supportedversions_compatibility.html

@ -0,0 +1,31 @@
<B_compatibility>
<table class="spip supportedversions">
<thead>
<BOUCLE_compatibility_head(DATA){source table, #NULL|SupportedVersions::phpMatrixWithEol}{0,1}>
<tr>
<th>&nbsp;</th>
<th style="text-align: center;" colspan="[(#VALEUR|count)]"><:supportedversions:php_compatibility:></th>
</tr>
<tr>
<th>SPIP</th>
<BOUCLE_matrix_head(DATA){source table, #VALEUR|array_keys}>
<th>#VALEUR</th>
</BOUCLE_matrix_head>
</tr>
</BOUCLE_compatibility_head>
</thead>
<BOUCLE_compatibility(DATA){source table, #NULL|SupportedVersions::phpMatrixWithEol}>
<tr>
<td>#CLE</td>
<BOUCLE_matrix(DATA){source table, #VALEUR}>
<td>
[(#VALEUR|?{
<span title="<:item_oui:>" style="color: #6f9271;">&#x2714;</span>,
<span title="<:item_non:>" style="color: #750f0f;">&#x2718;</span>
})]
</td>
</BOUCLE_matrix>
</tr>
</BOUCLE_compatibility>
</table>
</B_compatibility>

59
supportedversions_fonctions.php

@ -238,6 +238,65 @@ class SupportedVersions
);
}
/**
* Filtre fournissant un tableau de compatibilité SPIP/PHP.
*
* Conditions d'affichage:
* - une date de release initiale effective ou prévue est définie (non vide)
* - une liste de versions compatible pour PHP est fournie (non vide)
* - la date de fin de vie n'est pas communiquée (cas nominal)
*
* Si les versions en fin de vie sont demandées, la date de fin de vie
* doit être fournie et inférieure à la date du jour
*
* @param bool $eol true si on souahite afficher les versions SPIP en fin de vie.
* @return array<mixed>
*/
public static function phpMatrix($eol = false) {
// @codeCoverageIgnoreStart
if (!self::$config) {
self::init();
}
// @codeCoverageIgnoreEnd
$matrix = [];
$now = self::$now->format('Y-m-d');
$phpVersions = array_values(
array_unique(
array_reduce(
self::$releases,
function ($versions, $release) {
return array_merge($versions, $release['php']);
},
[]
)
)
);
foreach (self::$releases as $release) {
$toPrint = $release['initial_release'] !== '' && !empty($release['php']);
if (!$eol && $release['eol'] !== '') {
$toPrint = $toPrint && $release['eol'] >= $now;
}
if ($toPrint) {
foreach ($phpVersions as $php) {
$matrix[$release['branch']][$php] = in_array($php, $release['php']);
}
}
}
return $matrix;
}
/**
* @codeCoverageIgnore
* @return array<mixed>
*/
public static function phpMatrixWithEol() {
return self::phpMatrix(true);
}
//Calendar Part
/**

49
tests/SupportedVersionsTest.php

@ -222,6 +222,55 @@ class SupportedVersionsTest extends TestCase
));
}
public function dataPhpMatrix()
{
return [
'without-eol' => [[
'4.0' => [
'1.0' => true,
'2.0' => false,
],
'4.1' => [
'1.0' => true,
'2.0' => true,
],
], false],
'with-eol' => [[
'1.0' => [
'1.0' => true,
'2.0' => false,
],
'4.0' => [
'1.0' => true,
'2.0' => false,
],
'4.1' => [
'1.0' => true,
'2.0' => true,
],
], true],
];
}
/**
* @group criteres
* @dataProvider dataPhpMatrix
*/
public function testPhpMatrix($expected, $eol)
{
//Given
SupportedVersions::setConfig(
$this->calendarConfig,
$this->now,
);
//When
$matrix = SupportedVersions::phpMatrix($eol);
//Then
$this->assertEquals($expected, $matrix);
}
public function dataSupportedVersionsStateOrGradient()
{
return [

33
tests/releases/init.json

@ -3,66 +3,77 @@
"branch": "0.1",
"initial_release": "1969-02-03",
"active_support": "",
"eol": "1969-06-06"
"eol": "1969-06-06",
"php": []
},
{
"branch": "0.8",
"initial_release": "1969-09-03",
"active_support": "1971-02-03",
"eol": "1971-02-03"
"eol": "1971-02-03",
"php": []
},
{
"branch": "0.9",
"initial_release": "1969-11-05",
"active_support": "",
"eol": ""
"eol": "",
"php": []
},
{
"branch": "1.0",
"initial_release": "1971-02-03",
"active_support": "1971-06-06",
"eol": "1971-10-07"
"eol": "1971-10-07",
"php": ["1.0"]
},
{
"branch": "1.1",
"initial_release": "1971-06-06",
"active_support": "1971-10-07",
"eol": "1972-02-03"
"eol": "1972-02-03",
"php": []
},
{
"branch": "2.0",
"initial_release": "1971-07-01",
"active_support": "1972-03-09",
"eol": "1972-11-05"
"eol": "1972-11-05",
"php": []
},
{
"branch": "2.1",
"initial_release": "1971-10-07",
"active_support": "1972-06-06",
"eol": ""
"eol": "",
"php": []
},
{
"branch": "3.0",
"initial_release": "1972-03-01",
"active_support": "1972-11-05",
"eol": "1973-07-01"
"eol": "1973-07-01",
"php": []
},
{
"branch": "4.0",
"initial_release": "1971-11-06",
"active_support": "",
"eol": ""
"eol": "",
"php": ["1.0"]
},
{
"branch": "4.1",
"initial_release": "1971-12-01",
"active_support": "1971-12-01",
"eol": "1971-12-01"
"eol": "1971-12-01",
"php": ["1.0", "2.0"]
},
{
"branch": "5.0",
"initial_release": "",
"active_support": "",
"eol": ""
"eol": "",
"php": []
}
]

Loading…
Cancel
Save