]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
application: move checkPHPVersion from Utils to ApplicationUtils 389/head
authorVirtualTam <virtualtam@flibidi.net>
Tue, 24 Nov 2015 00:36:12 +0000 (01:36 +0100)
committerVirtualTam <virtualtam@flibidi.net>
Tue, 24 Nov 2015 00:40:44 +0000 (01:40 +0100)
Relates to #372

Signed-off-by: VirtualTam <virtualtam@flibidi.net>
application/ApplicationUtils.php
application/Utils.php
index.php
tests/ApplicationUtilsTest.php
tests/UtilsTest.php

index 6fb07f36fb3ff828b4ca1e6400fc705818ef93b3..b0e94e24429cedbbd1645773e8d5e5525b5d6ae7 100644 (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
      *
index 120333c560c93c29cf33a6e6175f829ae26ca6a4..b8579b4864f174503e9c5dae4c1351999a487a2a 100644 (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.
  *
index 654f7f8f36fabb83b84f2e0016b67a8d82e8866b..aae477bf7ec36b9f647d2addcc6c26929db994d9 100644 (file)
--- a/index.php
+++ b/index.php
@@ -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();
index 9a99c6c6684b0d00617f53ed55935ec8c226b27c..01301e689dec6bc47b12dc59aa68b585cd7cd860 100644 (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
      */
index 311d4bfb4979016146549518637f9af931e2b3e3..4847ea94de299b450c58fa8d13b9cbb92ebe7394 100644 (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!
      *