Unit Tests
parent
fd120251fc
commit
bf6841baea
File diff suppressed because it is too large
Load Diff
@ -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>
|
@ -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);
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../supportedversions_fonctions.php';
|
@ -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": ""
|
||||
}
|
||||
]
|
@ -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…
Reference in New Issue