Skip to content

Commit 20baf6f

Browse files
acoultoncraig410
authored andcommitted
Prove that DbBackedMutexWrapper is broken on 8.1
Due to PDO_MYSQL changing behaviour and returning ints as ints instead of strings. Obviously can't actually prove this on a DB connection in these unit tests, but the mock now mirrors PDO behaviour depending on PHP version.
1 parent 5cd3e76 commit 20baf6f

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

test/unit/Mutex/BasicPDOStatementStub.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ public function __construct(array $result) { $this->result = $result; }
4040

4141
public function fetchAll(int $fetch_style = NULL, mixed ...$fetch_argument): array
4242
{
43+
if (PHP_VERSION_ID < 80100) {
44+
// Before 8.1, ints and floats were returned as strings
45+
// https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.mysql
46+
$this->result = array_map(
47+
fn($row) => array_map(
48+
fn($column) => (is_int($column) || \is_float($column)) ? (string) $column : $column,
49+
$row
50+
),
51+
$this->result
52+
);
53+
}
54+
4355
if ($fetch_style === NULL) {
4456
return $this->result;
4557
} elseif ($fetch_style === PDO::FETCH_COLUMN) {
@@ -51,4 +63,4 @@ public function fetchAll(int $fetch_style = NULL, mixed ...$fetch_argument): arr
5163

5264

5365
}
54-
}
66+
}

test/unit/Mutex/DbBackedMutexWrapperTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public function test_it_requests_lock_and_throws_if_not_available_without_runnin
2929
[
3030
[
3131
'sql' => 'SELECT GET_LOCK({quoted-mylock}, 5)',
32-
'result' => [['0']]
32+
'result' => [[0]]
3333
],
3434
[
3535
'sql' => 'SELECT RELEASE_LOCK({quoted-mylock})',
36-
'result' => [['0']]
36+
'result' => [[0]]
3737
],
3838
]
3939
);
@@ -53,11 +53,11 @@ public function test_it_releases_lock_after_successful_callback_and_returns_resu
5353
[
5454
[
5555
'sql' => 'SELECT GET_LOCK({quoted-somelock}, 2)',
56-
'result' => [['1']]
56+
'result' => [[1]]
5757
],
5858
[
5959
'sql' => 'SELECT RELEASE_LOCK({quoted-somelock})',
60-
'result' => [['0']]
60+
'result' => [[0]]
6161
],
6262
]
6363
);
@@ -80,11 +80,11 @@ public function test_it_releases_lock_after_failed_callback_and_bubbles()
8080
[
8181
[
8282
'sql' => 'SELECT GET_LOCK({quoted-somelock}, 2)',
83-
'result' => [['1']]
83+
'result' => [[1]]
8484
],
8585
[
8686
'sql' => 'SELECT RELEASE_LOCK({quoted-somelock})',
87-
'result' => [['0']]
87+
'result' => [[0]]
8888
],
8989
]
9090
);

0 commit comments

Comments
 (0)