Merge pull request #389 from virtualtam/utils/check-php-version

application: move checkPHPVersion from Utils to ApplicationUtils
This commit is contained in:
VirtualTam 2015-11-24 01:42:52 +01:00
commit 4409b9eb0f
5 changed files with 52 additions and 52 deletions

View file

@ -5,6 +5,26 @@
class ApplicationUtils
{
/**
* Checks the PHP version to ensure Shaarli can run
*
* @param string $minVersion minimum PHP required version
* @param string $curVersion current PHP version (use PHP_VERSION)
*
* @throws Exception the PHP version is not supported
*/
public static function checkPHPVersion($minVersion, $curVersion)
{
if (version_compare($curVersion, $minVersion) < 0) {
throw new Exception(
'Your PHP version is obsolete!'
.' Shaarli requires at least PHP '.$minVersion.', and thus cannot run.'
.' Your PHP version has known security vulnerabilities and should be'
.' updated as soon as possible.'
);
}
}
/**
* Checks Shaarli has the proper access permissions to its resources
*

View file

@ -119,26 +119,6 @@ function generateLocation($referer, $host, $loopTerms = array())
return $finalReferer;
}
/**
* Checks the PHP version to ensure Shaarli can run
*
* @param string $minVersion minimum PHP required version
* @param string $curVersion current PHP version (use PHP_VERSION)
*
* @throws Exception the PHP version is not supported
*/
function checkPHPVersion($minVersion, $curVersion)
{
if (version_compare($curVersion, $minVersion) < 0) {
throw new Exception(
'Your PHP version is obsolete!'
.' Shaarli requires at least PHP '.$minVersion.', and thus cannot run.'
.' Your PHP version has known security vulnerabilities and should be'
.' updated as soon as possible.'
);
}
}
/**
* Validate session ID to prevent Full Path Disclosure.
*

View file

@ -159,7 +159,7 @@ require_once 'application/Router.php';
// Ensure the PHP version is supported
try {
checkPHPVersion('5.3', PHP_VERSION);
ApplicationUtils::checkPHPVersion('5.3', PHP_VERSION);
} catch(Exception $exc) {
header('Content-Type: text/plain; charset=utf-8');
echo $exc->getMessage();

View file

@ -11,6 +11,37 @@ require_once 'application/ApplicationUtils.php';
*/
class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
{
/**
* Check supported PHP versions
*/
public function testCheckSupportedPHPVersion()
{
$minVersion = '5.3';
ApplicationUtils::checkPHPVersion($minVersion, '5.4.32');
ApplicationUtils::checkPHPVersion($minVersion, '5.5');
ApplicationUtils::checkPHPVersion($minVersion, '5.6.10');
}
/**
* Check a unsupported PHP version
* @expectedException Exception
* @expectedExceptionMessageRegExp /Your PHP version is obsolete/
*/
public function testCheckSupportedPHPVersion51()
{
ApplicationUtils::checkPHPVersion('5.3', '5.1.0');
}
/**
* Check another unsupported PHP version
* @expectedException Exception
* @expectedExceptionMessageRegExp /Your PHP version is obsolete/
*/
public function testCheckSupportedPHPVersion52()
{
ApplicationUtils::checkPHPVersion('5.3', '5.2');
}
/**
* Checks resource permissions for the current Shaarli installation
*/

View file

@ -138,37 +138,6 @@ class UtilsTest extends PHPUnit_Framework_TestCase
$this->assertEquals('?', generateLocation($ref, 'localhost'));
}
/**
* Check supported PHP versions
*/
public function testCheckSupportedPHPVersion()
{
$minVersion = '5.3';
checkPHPVersion($minVersion, '5.4.32');
checkPHPVersion($minVersion, '5.5');
checkPHPVersion($minVersion, '5.6.10');
}
/**
* Check a unsupported PHP version
* @expectedException Exception
* @expectedExceptionMessageRegExp /Your PHP version is obsolete/
*/
public function testCheckSupportedPHPVersion51()
{
checkPHPVersion('5.3', '5.1.0');
}
/**
* Check another unsupported PHP version
* @expectedException Exception
* @expectedExceptionMessageRegExp /Your PHP version is obsolete/
*/
public function testCheckSupportedPHPVersion52()
{
checkPHPVersion('5.3', '5.2');
}
/**
* Test is_session_id_valid with a valid ID - TEST ALL THE HASHES!
*