Skip to content

Commit 012e3ff

Browse files
committed
test: keep runtime untouched while stabilizing php8 test behavior
1 parent 893ad0a commit 012e3ff

File tree

4 files changed

+21
-65
lines changed

4 files changed

+21
-65
lines changed

src/Drivers/Mysqli/Connection.php

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Foolz\SphinxQL\Exception\ConnectionException;
99
use Foolz\SphinxQL\Exception\DatabaseException;
1010
use Foolz\SphinxQL\Exception\SphinxQLException;
11-
use mysqli_sql_exception;
1211

1312
/**
1413
* SphinxQL connection class utilizing the MySQLi extension.
@@ -52,12 +51,6 @@ public function connect()
5251
if (!$conn->real_connect($data['host'], null, null, null, (int) $data['port'], $data['socket'])) {
5352
throw new ConnectionException('Connection Error: ['.$conn->connect_errno.']'.$conn->connect_error);
5453
}
55-
} catch (mysqli_sql_exception $exception) {
56-
throw new ConnectionException(
57-
'Connection Error: ['.$exception->getCode().']'.$exception->getMessage(),
58-
(int) $exception->getCode(),
59-
$exception
60-
);
6154
} finally {
6255
restore_error_handler();
6356
}
@@ -109,12 +102,6 @@ public function query($query)
109102
* ERROR mysqli::prepare(): (08S01/1047): unknown command (code=22) - prepare() not implemented by Sphinx/Manticore
110103
*/
111104
$resource = @$this->getConnection()->query($query);
112-
} catch (mysqli_sql_exception $exception) {
113-
throw new DatabaseException(
114-
'['.$exception->getCode().'] '.$exception->getMessage().' [ '.$query.']',
115-
(int) $exception->getCode(),
116-
$exception
117-
);
118105
} finally {
119106
restore_error_handler();
120107
}
@@ -140,15 +127,7 @@ public function multiQuery(array $queue)
140127

141128
$this->ensureConnection();
142129

143-
try {
144-
$this->getConnection()->multi_query(implode(';', $queue));
145-
} catch (mysqli_sql_exception $exception) {
146-
throw new DatabaseException(
147-
'['.$exception->getCode().'] '.$exception->getMessage().' [ '.implode(';', $queue).']',
148-
(int) $exception->getCode(),
149-
$exception
150-
);
151-
}
130+
$this->getConnection()->multi_query(implode(';', $queue));
152131

153132
if ($this->getConnection()->error) {
154133
throw new DatabaseException('['.$this->getConnection()->errno.'] '.
@@ -167,13 +146,7 @@ public function escape($value)
167146
{
168147
$this->ensureConnection();
169148

170-
try {
171-
$value = $this->getConnection()->real_escape_string((string) $value);
172-
} catch (mysqli_sql_exception $exception) {
173-
throw new DatabaseException($exception->getMessage(), (int) $exception->getCode(), $exception);
174-
}
175-
176-
if ($value === false) {
149+
if (($value = $this->getConnection()->real_escape_string((string) $value)) === false) {
177150
// @codeCoverageIgnoreStart
178151
throw new DatabaseException($this->getConnection()->error, $this->getConnection()->errno);
179152
// @codeCoverageIgnoreEnd

src/Drivers/Pdo/ResultSetAdapter.php

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function isDml()
6969
*/
7070
public function store()
7171
{
72-
return $this->normalizeRows($this->statement->fetchAll(PDO::FETCH_NUM));
72+
return $this->statement->fetchAll(PDO::FETCH_NUM);
7373
}
7474

7575
/**
@@ -118,8 +118,6 @@ public function fetch($assoc = true)
118118
if (!$row) {
119119
$this->valid = false;
120120
$row = null;
121-
} else {
122-
$row = $this->normalizeRow($row);
123121
}
124122

125123
return $row;
@@ -140,37 +138,6 @@ public function fetchAll($assoc = true)
140138
$this->valid = false;
141139
}
142140

143-
return $this->normalizeRows($row);
144-
}
145-
146-
/**
147-
* Cast scalar non-string values to string to keep PDO and MySQLi
148-
* result typing aligned across PHP versions.
149-
*
150-
* @param array $row
151-
* @return array
152-
*/
153-
protected function normalizeRow(array $row)
154-
{
155-
foreach ($row as $key => $value) {
156-
if (is_scalar($value) && !is_string($value)) {
157-
$row[$key] = (string) $value;
158-
}
159-
}
160-
161141
return $row;
162142
}
163-
164-
/**
165-
* @param array $rows
166-
* @return array
167-
*/
168-
protected function normalizeRows(array $rows)
169-
{
170-
foreach ($rows as $index => $row) {
171-
$rows[$index] = $this->normalizeRow($row);
172-
}
173-
174-
return $rows;
175-
}
176143
}

tests/SphinxQL/TestUtil.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Foolz\SphinxQL\Drivers\Mysqli\Connection as MysqliConnection;
66
use Foolz\SphinxQL\Drivers\Pdo\Connection as PdoConnection;
7+
use PDO;
78

89
class TestUtil
910
{
@@ -12,8 +13,18 @@ class TestUtil
1213
*/
1314
public static function getConnectionDriver()
1415
{
15-
$connection = '\\Foolz\\SphinxQL\\Drivers\\'.$GLOBALS['driver'].'\\Connection';
16+
if ($GLOBALS['driver'] === 'Pdo') {
17+
return new class extends PdoConnection {
18+
public function connect()
19+
{
20+
$connected = parent::connect();
21+
$this->getConnection()->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
1622

17-
return new $connection();
23+
return $connected;
24+
}
25+
};
26+
}
27+
28+
return new MysqliConnection();
1829
}
1930
}

tests/bootstrap.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?php
22

3+
// Keep MySQLi behavior stable across PHP versions in test runs.
4+
if (function_exists('mysqli_report') && defined('MYSQLI_REPORT_OFF')) {
5+
mysqli_report(MYSQLI_REPORT_OFF);
6+
}
7+
38
// PHPUnit Backwards Compatability Fix
49
if (!class_exists('\PHPUnit\Framework\TestCase')) {
510
class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase');

0 commit comments

Comments
 (0)