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
*
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.
*
// 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();
*/
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
*/
$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!
*