Browse Source

Unit Tests

merge-requests/10/merge
James 2 years ago
parent
commit
bf6841baea
  1. 9
      .editorconfig
  2. 2
      .gitignore
  3. 38
      CHANGELOG
  4. 2
      README.md
  5. 10
      composer.json
  6. 2020
      composer.lock
  7. 86
      phpcs.xml.dist
  8. 37
      phpunit.xml.dist
  9. 138
      supportedversions_fonctions.php
  10. 34
      tests/FunctionsTest.php
  11. 33
      tests/SupportedVersions.php
  12. 386
      tests/SupportedVersionsTest.php
  13. 28
      tests/TestCase.php
  14. 4
      tests/bootstrap.php
  15. 27
      tests/releases/init.json
  16. 13
      tests/sdk.php

9
.editorconfig

@ -6,3 +6,12 @@ insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
indent_style = tab
[composer.json]
indent_style = space
[CHANGELOG, *.md]
indent_size = 2
[*.xml]
indent_style = space

2
.gitignore vendored

@ -2,3 +2,5 @@
/.php_cs.cache
/php_cs.txt
/php_cs.xml
/.phpunit.cache/
/phpunit.xml

38
CHANGELOG

@ -1,4 +1,5 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
@ -6,44 +7,53 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
- table model displays the last release date and the version number over the branch name
### Added
- `<supportedversions|latest`> model
- `<supportedversions|eol`> model
- `<supportedversions|latest>` model
- `<supportedversions|eol>` model
- Unit Tests with PHPUnit
## [0.2.4] - 2020-10-02
### Changed
- releases upgrades
- releases upgrades (SPIP3.1.14)
## [0.2.3] - 2020-09-30
### Changed
- releases upgrades
- releases upgrades (SPIP3.2.8 and SPIP3.1.13)
## [0.2.1] - 2020-08-21
### Added
### Fixed
- releases exposition
## [0.2.0] - 2020-07-05
### Changed
- i18n updates
- releases upgrades
### Added
- `<supportedversions|releases`> model
- `releases.json` page
## [0.1.0] - 2019-03-17
### Added
- `#SUPPORTED_VERSIONS` tag
- `SupportedVersions` Filters class wich includes :
- `state`
- `top` and `topForText`
- `width` and `height`
- `branchesToShow`
- `years`
- `horizCoord`
- `stableOrGradient`
- `securityOrGradient`
- `<supportedversions|table`>`, `<supportedversions|calendar`>` and `<supportedversions|legend`>` models
- `state`
- `top` and `topForText`
- `width` and `height`
- `branchesToShow`
- `years`
- `horizCoord`
- `stableOrGradient`
- `securityOrGradient`
- `<supportedversions|table>`, `<supportedversions|calendar>` and `<supportedversions|legend>` models
- `supported-versions.svg` page

2
README.md

@ -35,4 +35,4 @@ and call : `/releases.json`
- Hanjo for the Dutch translation
- Nicod_ for BEM and so much
- b_b & marcimat for thier support
- b_b & marcimat for their support

10
composer.json

@ -18,7 +18,15 @@
}
},
"require-dev": {
"php": "^7.3 || ^8.0",
"squizlabs/php_codesniffer": "^3.5",
"phpcompatibility/php-compatibility": "^9.3"
"phpcompatibility/php-compatibility": "^9.3",
"phpunit/phpunit": "^9.4"
},
"autoload-dev": {
"psr-4": {
"JamesRezo\\SupportedVersions\\Test\\": "tests/"
},
"files": ["tests/sdk.php"]
}
}

2020
composer.lock generated

File diff suppressed because it is too large Load Diff

86
phpcs.xml.dist

@ -1,54 +1,55 @@
<?xml version="1.0"?>
<ruleset name="SPIP">
<description>Coding rules for SPIP</description>
<description>Coding rules for SPIP</description>
<file>./</file>
<exclude-pattern>lang/*</exclude-pattern>
<exclude-pattern>vendor/*</exclude-pattern>
<file>./</file>
<exclude-pattern>lang/*</exclude-pattern>
<exclude-pattern>vendor/*</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
<rule ref="PSR1" >
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
</rule>
<rule ref="PSR1" >
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
</rule>
<!-- Appliquer PSR-2 moins nos exceptions -->
<rule ref="PSR2" >
<!-- Désactiver la vérification sur les noms de classes/fonctions -->
<exclude name="Squiz.Classes.ValidClassName" />
<!-- Désactiver la vérification sur l'indentation -->
<exclude name="Generic.WhiteSpace.ScopeIndent" />
<exclude name="Generic.WhiteSpace.DisallowTabIndent" />
<!-- Désactiver la vérification sur les accolades -->
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine" />
<exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine" />
<exclude name="PSR2.Classes.PropertyDeclaration" />
</rule>
<!-- Appliquer PSR-2 moins nos exceptions -->
<rule ref="PSR2" >
<!-- Désactiver la vérification sur les noms de classes/fonctions -->
<exclude name="Squiz.Classes.ValidClassName" />
<!-- Désactiver la vérification sur l'indentation -->
<exclude name="Generic.WhiteSpace.ScopeIndent" />
<exclude name="Generic.WhiteSpace.DisallowTabIndent" />
<!-- Désactiver la vérification sur les accolades -->
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine" />
<exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine" />
<exclude name="PSR2.Classes.PropertyDeclaration" />
</rule>
<!-- Tabulations pour l'indentation -->
<arg name="tab-width" value="4"/>
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="indent" value="4"/>
<property name="tabIndent" value="true"/>
</properties>
</rule>
<!-- Tabulations pour l'indentation -->
<arg name="tab-width" value="4"/>
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="indent" value="4"/>
<property name="tabIndent" value="true"/>
</properties>
</rule>
<!-- Accolades -->
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie"/>
<rule ref="Generic.ControlStructures.InlineControlStructure" />
<rule ref="Squiz.ControlStructures.ControlSignature" />
<rule ref="Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace">
<severity>0</severity>
</rule>
<!-- Accolades -->
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie"/>
<rule ref="Generic.ControlStructures.InlineControlStructure" />
<rule ref="Squiz.ControlStructures.ControlSignature" />
<rule ref="Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace">
<severity>0</severity>
</rule>
<!-- Guillemets doubles -->
<rule ref="Squiz.Strings.DoubleQuoteUsage"/>
<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
<severity>0</severity>
</rule>
<!-- Guillemets doubles -->
<rule ref="Squiz.Strings.DoubleQuoteUsage"/>
<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
<severity>0</severity>
</rule>
<!-- Constantes en majuscules -->
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
<!-- Constantes en majuscules -->
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
<!-- Run against the PHPCompatibility ruleset -->
<rule ref="PHPCompatibility"/>
@ -62,5 +63,4 @@
<arg name="report-checkstyle" value="php_cs.xml"/>
<arg name="report-full" value="php_cs.txt"/>
<arg name="report-summary"/>
</ruleset>

37
phpunit.xml.dist

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.4/phpunit.xsd"
bootstrap="tests/bootstrap.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
verbose="true"
colors="true">
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">./</directory>
</include>
<exclude>
<file>supportedversions_options.php</file>
<directory suffix=".php">tests</directory>
<directory suffix=".php">lang</directory>
<directory suffix=".php">vendor</directory>
</exclude>
<report>
<html outputDirectory=".phpunit.cache/html"/>
<text outputFile="php://stdout"/>
</report>
</coverage>
</phpunit>

138
supportedversions_fonctions.php

@ -10,6 +10,12 @@ function supportedversions_insert_head_css($flux) {
return $flux;
}
/**
* @codeCoverageIgnore
*
* @param string $flux
* @return string
*/
function supportedversions_header_prive_css($flux) {
return supportedversions_insert_head_css($flux);
}
@ -23,39 +29,51 @@ function balise_SUPPORTED_VERSIONS_dist($p) {
*/
class SupportedVersions
{
private static $config = null;
private static $now;
protected static $config = null;
protected static $now;
private static $minDate;
private static $maxDate;
private static $years;
private static $releases;
private static $branches;
protected static $releasesFile;
/**
* @codeCoverageIgnore
*
* @return void
*/
protected static function init() {
self::$config = $GLOBALS['supportedversions'];
self::$now = new DateTime;
self::$releasesFile = 'data/releases.json';
self::$minDate = (new DateTime('January 1'))->sub(new DateInterval(self::$config['calendar']['min_year']));
self::$maxDate = (new DateTime('January 1'))->add(new DateInterval(self::$config['calendar']['max_year']));
self::compute();
}
protected static function compute() {
// Calendar initialization
$nowYear = self::$now->format('Y');
self::$minDate = (new DateTime('January 1 '.$nowYear))
->sub(new DateInterval(self::$config['calendar']['min_year']));
self::$maxDate = (new DateTime('January 1 '.$nowYear))
->add(new DateInterval(self::$config['calendar']['max_year']));
self::$years = array_map(
function ($year) {
return $year->format('Y-m-d');
},
iterator_to_array(new DatePeriod(self::$minDate, new DateInterval('P1Y'), self::$maxDate))
);
self::$releases = json_decode(file_get_contents(find_in_path('data/releases.json')), true);
self::$branches = array_map(
function ($branch) {
return $branch['branch'];
},
json_decode(file_get_contents(find_in_path('data/releases.json')), true)
);
// Releases initialization
self::$releases = json_decode(file_get_contents(find_in_path(self::$releasesFile)), true);
}
public static function branchesToShow($eol = false) {
// @codeCoverageIgnoreStart
if (!self::$config) {
self::init();
}
// @codeCoverageIgnoreEnd
$now = self::$now->format('Y-m-d');
return array_reduce(
@ -76,9 +94,11 @@ class SupportedVersions
}
public static function eoledBranches() {
// @codeCoverageIgnoreStart
if (!self::$config) {
self::init();
}
// @codeCoverageIgnoreEnd
$now = self::$now->format('Y-m-d');
return array_reduce(
@ -97,10 +117,6 @@ class SupportedVersions
//Calendar Part
protected static function dateHorizCoord(DateTime $date) {
if (!self::$config) {
self::init();
}
$diff = $date->diff(self::$minDate);
if (!$diff->invert) {
return self::$config['svg']['margin_left'];
@ -111,14 +127,22 @@ class SupportedVersions
}
public static function years() {
// @codeCoverageIgnoreStart
if (!self::$config) {
self::init();
}
// @codeCoverageIgnoreEnd
return self::$years;
}
public static function horizCoord($date) {
// @codeCoverageIgnoreStart
if (!self::$config) {
self::init();
}
// @codeCoverageIgnoreEnd
if ($date) {
return self::dateHorizCoord(date_create_from_format('Y-m-d', $date));
}
@ -128,29 +152,63 @@ class SupportedVersions
//SVG Part
/**
* Filtre qui détermine l'état d'une version par rapport à la date du jour.
*
* le tableau de valeurs doit impérativement contenir les clés suivantes:
*
* initial_release:
* Une date au format 'Y-m-d' indiquant la date de sortie de la première release stable (X.Y.0)
* Si la date est vide (''), la version n'a pas de date de sortie prévue, l'état est 'future'
* Si la date est supérieure à la date du jour, l'état est 'future'
* Sinon elle est 'stable'
*
* active_support:
* Une date indiquant le moment ou seuls des correctifs de sécurité sont assurés pour la version
* Si la date est vide (''), la version n'a pas de date de fin de support actif prévue, l'état reste à 'stable'
* Si la date est supérieure à la date du jour, l'état reste à 'stable'
* Sinon l'état est 'security'
*
* eol:
* Une date à partir de laquelle il n'y a plus de mise à jour pour la version
* Si la date est vide (''), la version n'a pas de date de fin de vie prévue, l'état reste à 'security'
* Si la date est supérieure à la date du jour, l'état reste à 'security'
* Sinon l'état est 'eol'
*
* @param array $valeurs tableau correspondant aux dates de la version
* @return void
*/
public static function state(array $valeurs) {
self::$now = new DateTime;
$initial = new DateTime($valeurs['initial_release']);
// @codeCoverageIgnoreStart
if (!self::$config) {
self::init();
}
// @codeCoverageIgnoreEnd
$state = 'future';
$initial = $valeurs['initial_release'] ? new DateTime($valeurs['initial_release']) : null;
$bug = $valeurs['active_support'] ? new DateTime($valeurs['active_support']) : null;
$security = $valeurs['eol'] ? new DateTime($valeurs['eol']) : null;
if ($security && self::$now >= $security) {
$state = 'eol';
} elseif ($bug && self::$now >= $bug) {
$state = 'security';
} elseif (self::$now >= $initial) {
if ($initial && $initial < self::$now) {
$state = 'stable';
} else {
$state = 'future';
}
if ($bug && $bug < self::$now) {
$state = 'security';
}
if ($security && $security < self::$now) {
$state = 'eol';
}
return $state;
}
public static function top($branch) {
// @codeCoverageIgnoreStart
if (!self::$config) {
self::init();
}
// @codeCoverageIgnoreEnd
$branches = array_map(
function ($branch) {
@ -160,9 +218,15 @@ class SupportedVersions
);
$i = array_search($branch, $branches, true);
return self::$config['svg']['header_height'] + (self::$config['svg']['branch_height'] * $i++);
return self::$config['svg']['header_height'] + (self::$config['svg']['branch_height'] * $i);
}
/**
* @codeCoverageIgnore
*
* @param string $branch
* @return void
*/
public static function topForText($branch) {
if (!self::$config) {
self::init();
@ -173,6 +237,12 @@ class SupportedVersions
return $top;
}
/**
* @codeCoverageIgnore
*
* @param int $margin_left
* @return void
*/
public static function width($margin_left) {
if (!self::$config) {
self::init();
@ -183,6 +253,12 @@ class SupportedVersions
((count(self::$years) - 1) * self::$config['svg']['year_width']);
}
/**
* @codeCoverageIgnore
*
* @param int $header_height
* @return void
*/
public static function height($header_height) {
if (!self::$config) {
self::init();
@ -194,6 +270,11 @@ class SupportedVersions
}
public static function stableOrGradient($date) {
// @codeCoverageIgnoreStart
if (!self::$config) {
self::init();
}
// @codeCoverageIgnoreEnd
$gradient = '';
if ($date == '' || new DateTime($date) > self::$maxDate) {
@ -204,6 +285,11 @@ class SupportedVersions
}
public static function securityOrGradient($date) {
// @codeCoverageIgnoreStart
if (!self::$config) {
self::init();
}
// @codeCoverageIgnoreEnd
$gradient = '';
if ($date == '' || new DateTime($date) > self::$maxDate) {

34
tests/FunctionsTest.php

@ -0,0 +1,34 @@
<?php
namespace JamesRezo\SupportedVersions\Test;
class FunctionsTest extends TestCase
{
/**
* @covers ::supportedversions_insert_head_css
*
* @return void
*/
public function testSupportedVersionsInsertHeadCss()
{
$flux = supportedversions_insert_head_css('test');
$this->assertEquals(
'test<link rel="stylesheet" type="text/css" media="all" href="css/supported-versions.css" />' . "\n",
$flux
);
}
/**
* @covers ::balise_SUPPORTED_VERSIONS_dist
*
* @return void
*/
public function testBaliseSupportedVersionsDist()
{
$champ = new \StdClass();
$champ = balise_SUPPORTED_VERSIONS_dist($champ);
$this->assertEquals('(is_array($a = ($GLOBALS["supportedversions"])) ? serialize($a) : "")', $champ->code);
}
}

33
tests/SupportedVersions.php

@ -0,0 +1,33 @@
<?php
namespace JamesRezo\SupportedVersions\Test;
use DateTime;
class SupportedVersions extends \SupportedVersions
{
public static function getConfig()
{
return [
'config' => self::$config,
'now' => self::$now,
'releasesFile' => self::$releasesFile,
];
}
public static function unsetConfig()
{
self::$config = null;
self::$now = null;
self::$releasesFile = null;
}
public static function setConfig(array $config = [], $now = '', $releasesFile = 'tests/releases/init.json')
{
self::$config = $config;
self::$now = new DateTime($now);
self::$releasesFile = $releasesFile;
self::compute();
}
}

386
tests/SupportedVersionsTest.php

@ -0,0 +1,386 @@
<?php
namespace JamesRezo\SupportedVersions\Test;
/**
* @covers \SupportedVersions
*/
class SupportedVersionsTest extends TestCase
{
public function dataSupportedVersionsState()
{
return [
'release-pas-prévue' => [
'future',
[
'initial_release' => '',
'active_support' => '',
'eol' => '',
],
],
'release-pas-sortie' => [
'future',
[
'initial_release' => '1971-12-01',
'active_support' => '',
'eol' => '',
],
],
'release-toujours-stable' => [
'stable',
[
'initial_release' => '1971-01-01',
'active_support' => '',
'eol' => '',
],
],
'release-bientot-en-maintenance' => [
'stable',
[
'initial_release' => '1971-01-01',
'active_support' => '1971-11-06',
'eol' => '',
],
],
'release-en-maintenance' => [
'security',
[
'initial_release' => '1971-01-01',
'active_support' => '1971-11-03',
'eol' => '',
],
],
'release-plus-maintenue' => [
'eol',
[
'initial_release' => '1971-01-01',
'active_support' => '1971-11-03',
'eol' => '1971-11-04',
],
],
];
}
/**
* @dataProvider dataSupportedVersionsState
*
* @param string $expected
* @param array $release
* @return void
*/
public function testSupportedVersionsState($expected, $release)
{
//Given
SupportedVersions::setConfig(
$this->calendarConfig,
$this->now,
);
//When
$state = SupportedVersions::state($release);
//Then
$this->assertEquals($expected, $state);
}
public function dataSupportedVersionsInit()
{
return [
'1-an-avant-annee-courante' => [
[
'1970-01-01',
'1971-01-01',
],
[
'calendar' => [
'min_year' => 'P1Y',
'max_year' => 'P1Y',
],
],
],
'1-an-avant-annee-courante-1-an-après' => [
[
'1970-01-01',
'1971-01-01',
'1972-01-01',
],
[
'calendar' => [
'min_year' => 'P1Y',
'max_year' => 'P2Y',
],
],
],
];
}
/**
* @dataProvider dataSupportedVersionsInit
*
* @param string $expected
* @param array $config
* @return void
*/
public function testSupportedVersionsInit($expected, $config)
{
//Given
SupportedVersions::setConfig($config, $this->now);
//When
$years = SupportedVersions::years();
//Then
$this->assertEquals($expected, $years);
}
public function dataSupportedVersionsBranchesToShow()
{
return [
'stables-seulement' => [
[
[
'branch' => '3.0',
'initial_release' => '1971-08-01',
'eol' => '',
],
],
false,
],
'toutes-versions-dans-l-intervalle-de-temps-' => [
[
[
'branch' => '1.0',
'initial_release' => '1971-02-03',
'eol' => '1971-06-06',
],
[
'branch' => '2.0',
'initial_release' => '1971-04-01',
'eol' => '1971-09-01',
],
[
'branch' => '3.0',
'initial_release' => '1971-08-01',
'eol' => '',
],
],
true,
],
];
}
/**
* @dataProvider dataSupportedVersionsBranchesToShow
*
* @param array $expected
* @param bool $eol
* @return void
*/
public function testSupportedVersionsBranchesToShow($expected, $eol)
{
//Given
SupportedVersions::setConfig(
$this->calendarConfig,
$this->now,
);
//When
$branches = SupportedVersions::branchesToShow($eol);
//Then
$this->assertEquals($expected, $branches);
}
public function dataSupportedVersionsEoledBranches()
{
return [
'nominal' => [
[
[
'branch' => '0.1',
'initial_release' => '1969-02-03',
'eol' => '1969-06-06'
],
[
'branch' => '1.0',
'initial_release' => '1971-02-03',
'eol' => '1971-06-06',
],
[
'branch' => '2.0',
'initial_release' => '1971-04-01',
'eol' => '1971-09-01',
],
],
[
'calendar' => [
'min_year' => 'P1Y',
'max_year' => 'P2Y',
],
],
],
];
}
/**
* @dataProvider dataSupportedVersionsEoledBranches
*
* @param array $expected
* @param array $config
* @return void
*/
public function testSupportedVersionsEoledBranches($expected, $config)
{
//Given
SupportedVersions::setConfig($config, $this->now);
//When
$branches = SupportedVersions::eoledBranches();
//Then
$this->assertEquals($expected, $branches);
}
public function dataSupportedVersionsSecurityOrGradient()
{
return [
'date-is-empty' => [
'security-gradient',
'',
],
'no-gradient' => [
'security',
'1971-01-01'
],
'out-of-scope-with-gradient' => [
'security-gradient',
'1974-01-01'
],
];
}
/**
* @dataProvider dataSupportedVersionsSecurityOrGradient
*
* @param string $expected
* @param string $date
* @return void
*/
public function testSupportedVersionsSecurityOrGradient($expected, $date)
{
//Given
SupportedVersions::setConfig(
$this->calendarConfig,
$this->now,
);
//When
$cssClass = SupportedVersions::securityOrGradient($date);
//Then
$this->assertEquals($expected, $cssClass);
}
/**
* @dataProvider dataSupportedVersionsSecurityOrGradient
*
* @param string $expected
* @param string $date
* @return void
*/
public function testSupportedVersionsStableOrGradient($expected, $date)
{
//Given
SupportedVersions::setConfig(
$this->calendarConfig,
$this->now,
);
$expected = str_replace('security', 'stable', $expected);
//When
$cssClass = SupportedVersions::stableOrGradient($date);
//Then
$this->assertEquals($expected, $cssClass);
}
public function dataSupportedVersionsHorizCoord()
{
return [
'date-is-empty' => [
868.1962545175775,
'',
],
'date-in-svg' => [
589.2344759610119,
'1971-11-30',
],
'date-out-svg' => [
100,
'1969-01-01',
],
];
}
/**
* @dataProvider dataSupportedVersionsHorizCoord
*
* @param float $expected
* @param string $date
* @return void
*/
public function testSupportedVersionsHorizCoord($expected, $date)
{
//Given
SupportedVersions::setConfig(
array_merge($this->svgConfig, $this->calendarConfig),
$this->now
);
//When
$horizCoord = SupportedVersions::horizCoord($date);
//Then
$this->assertEquals($expected, $horizCoord);
}
public function dataSupportedVersionsTop()
{
return [
'branch-not-set' => [
48,
'',
],
'branch-not-exist' => [
48,
'0.2',
],
'branch-exists' => [
112,
'2.0',
],
];
}
/**
* @dataProvider dataSupportedVersionsTop
*
* @param int $expected
* @param string $branch
* @return void
*/
public function testSupportedVersionsTop($expected, $branch)
{
//Given
SupportedVersions::setConfig(
array_merge($this->svgConfig, $this->calendarConfig),
$this->now
);
//When
$actual = SupportedVersions::top($branch);
//Then
$this->assertEquals($expected, $actual);
}
}

28
tests/TestCase.php

@ -0,0 +1,28 @@
<?php
namespace JamesRezo\SupportedVersions\Test;
use DateTime;
use PHPUnit\Framework\TestCase as BaseTestCase;
class TestCase extends BaseTestCase
{
protected $now = '1971-11-05 18:40:12.345678Z';
protected $calendarConfig = ['calendar' => ['min_year' => 'P1Y', 'max_year' => 'P2Y']];
protected $svgConfig = [
'svg' => [
'margin_left' => 100,
'margin_right' => 100,
'year_width' => 256,
'header_height' => 48,
'branch_height' => 64,
],
];
protected function tearDown(): void
{
SupportedVersions::unsetConfig();
}
}

4
tests/bootstrap.php

@ -0,0 +1,4 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../supportedversions_fonctions.php';

27
tests/releases/init.json

@ -0,0 +1,27 @@
[
{
"branch": "0.1",
"initial_release": "1969-02-03",
"eol": "1969-06-06"
},
{
"branch": "1.0",
"initial_release": "1971-02-03",
"eol": "1971-06-06"
},
{
"branch": "2.0",
"initial_release": "1971-04-01",
"eol": "1971-09-01"
},
{
"branch": "3.0",
"initial_release": "1971-08-01",
"eol": ""
},
{
"branch": "4.0",
"initial_release": "",
"eol": ""
}
]

13
tests/sdk.php

@ -0,0 +1,13 @@
<?php
function find_in_path($fileName)
{
return $fileName;
}
function balise_ENV_dist($p, $src = '')
{
$p->code = '(is_array($a = (' . $src . ')) ? serialize($a) : "")';
return $p;
}
Loading…
Cancel
Save