Bläddra i källkod

Merge pull request #1734 from PrivateBin/php85

Enable PHP 8.5 testing and handle deprecations
El RIDO 7 månader sedan
förälder
incheckning
52c0846dad
3 ändrade filer med 15 tillägg och 5 borttagningar
  1. 2 2
      .github/workflows/tests.yml
  2. 7 2
      lib/Data/Database.php
  3. 6 1
      tst/ControllerTest.php

+ 2 - 2
.github/workflows/tests.yml

@@ -27,11 +27,11 @@ jobs:
     continue-on-error: "${{ matrix.experimental }}"
     strategy:
       matrix:
-        php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
+        php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
         experimental: [false]
 # uncomment this to start testing on development release
 #        include:
-#          - php-versions: '8.5' # development release, things can break
+#          - php-versions: '8.6' # development release, things can break
 #            experimental: true
     env:
       extensions: gd, sqlite3

+ 7 - 2
lib/Data/Database.php

@@ -84,8 +84,13 @@ class Database extends AbstractData
             );
             // MySQL uses backticks to quote identifiers by default,
             // tell it to expect ANSI SQL double quotes
-            if ($this->_type === 'mysql' && defined('PDO::MYSQL_ATTR_INIT_COMMAND')) {
-                $options['opt'][PDO::MYSQL_ATTR_INIT_COMMAND] = "SET SESSION sql_mode='ANSI_QUOTES'";
+            if ($this->_type === 'mysql') {
+                // deprecated as of PHP 8.5
+                if (version_compare(PHP_VERSION, '8.5') < 0 && defined('PDO::MYSQL_ATTR_INIT_COMMAND')) {
+                    $options['opt'][PDO::MYSQL_ATTR_INIT_COMMAND] = "SET SESSION sql_mode='ANSI_QUOTES'";
+                } elseif (defined('Pdo\Mysql::ATTR_INIT_COMMAND')) {
+                    $options['opt'][Pdo\Mysql::ATTR_INIT_COMMAND] = "SET SESSION sql_mode='ANSI_QUOTES'";
+                }
             }
             $tableQuery = $this->_getTableQuery($this->_type);
             $this->_db  = new PDO(

+ 6 - 1
tst/ControllerTest.php

@@ -155,7 +155,12 @@ class ControllerTest extends TestCase
     {
         $newConfig   = new class extends Configuration {};
         $configValue = (new ReflectionClass(Controller::class))->getProperty('_conf');
-        $configValue->setAccessible(true);
+        if (version_compare(PHP_VERSION, '8.1') < 0) {
+            // > This function has been DEPRECATED as of PHP 8.5.0. [...]
+            // > As of PHP 8.1.0, calling this method has no effect; all properties are accessible by default.
+            // @see: https://www.php.net/manual/en/reflectionproperty.setaccessible.php
+            $configValue->setAccessible(true);
+        }
         ob_start();
         $controller = new Controller($newConfig);
         ob_end_clean();