Skip to content

Commit d9f6508

Browse files
Fixing deprecation in PHP 8.5 (#86)
* Fixing deprecation in PHP 8.5 * Removed ancient code sniffer. * Skip DNS resoultion failure.
1 parent 5b6a103 commit d9f6508

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

composer.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
"ext-intl": "Required to use IntlDateFormatter instead of strftime, if not Symfony polyfill will be used."
3030
},
3131
"require-dev": {
32-
"phpunit/phpunit": "^9.5",
33-
"cakephp/cakephp-codesniffer": "^1.0.0"
32+
"phpunit/phpunit": "^9.5"
3433
},
3534
"config": {
3635
"vendor-dir": "vendors/",
@@ -41,10 +40,8 @@
4140
],
4241
"scripts": {
4342
"check": [
44-
"@cs-check",
4543
"@test"
4644
],
47-
"cs-check": "./vendors/bin/phpcs -p --extensions=php --standard=CakePHP ./lib/Cake",
4845
"test": "./lib/Cake/Console/cake test core AllTests --stderr --verbose"
4946
}
5047
}

lib/Cake/Model/Datasource/Database/Mysql.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,23 @@ public function connect() {
161161
$config = $this->config;
162162
$this->connected = false;
163163

164+
// PDO::MYSQL_ATTR_* constants are deprecated in PHP 8.5; Pdo\Mysql class is available since PHP 8.1
165+
if (class_exists('Pdo\Mysql')) {
166+
$mysqlAttrUseBufferedQuery = Pdo\Mysql::ATTR_USE_BUFFERED_QUERY;
167+
$mysqlAttrInitCommand = Pdo\Mysql::ATTR_INIT_COMMAND;
168+
} else {
169+
$mysqlAttrUseBufferedQuery = PDO::MYSQL_ATTR_USE_BUFFERED_QUERY;
170+
$mysqlAttrInitCommand = PDO::MYSQL_ATTR_INIT_COMMAND;
171+
}
172+
164173
$flags = $config['flags'] + array(
165174
PDO::ATTR_PERSISTENT => $config['persistent'],
166-
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
175+
$mysqlAttrUseBufferedQuery => true,
167176
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
168177
);
169178

170179
if (!empty($config['encoding'])) {
171-
$flags[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $config['encoding'];
180+
$flags[$mysqlAttrInitCommand] = 'SET NAMES ' . $config['encoding'];
172181
}
173182
if (!empty($config['ssl_key']) && !empty($config['ssl_cert'])) {
174183
$flags[PDO::MYSQL_ATTR_SSL_KEY] = $config['ssl_key'];

lib/Cake/Test/Case/Network/Http/HttpSocketTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,7 @@ public function testVerifyPeer() {
18451845
} catch (SocketException $e) {
18461846
$message = $e->getMessage();
18471847
$this->skipIf(strpos($message, 'Invalid HTTP') !== false, 'Invalid HTTP Response received, skipping.');
1848+
$this->skipIf(strpos($message, 'getaddrinfo') !== false, 'Could not resolve host, network unavailable, skipping.');
18481849
$this->assertStringContainsString('Failed to enable crypto', $message);
18491850
}
18501851
}

0 commit comments

Comments
 (0)