Skip to content

Commit 2d28a4e

Browse files
committed
Fix test assertions for PDO::FETCH_NAMED
1 parent ba5b0ce commit 2d28a4e

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

tests/WP_PDO_MySQL_On_SQLite_PDO_API_Tests.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public function test_query_with_fetch_mode( $query, $mode, $expected ): void {
6363
if ( is_object( $expected ) ) {
6464
$this->assertInstanceOf( get_class( $expected ), $result );
6565
$this->assertEquals( $expected, $result );
66+
} elseif ( PDO::FETCH_NAMED === $mode ) {
67+
// PDO::FETCH_NAMED returns all array keys as strings, even numeric
68+
// ones. This is not possible in plain PHP and might be a PDO bug.
69+
$this->assertSame( array_map( 'strval', array_keys( $expected ) ), array_keys( $result ) );
70+
$this->assertSame( array_values( $expected ), array_values( $result ) );
6671
} else {
6772
$this->assertSame( $expected, $result );
6873
}
@@ -249,6 +254,11 @@ public function test_fetch( $query, $mode, $expected ): void {
249254
if ( is_object( $expected ) ) {
250255
$this->assertInstanceOf( get_class( $expected ), $result );
251256
$this->assertEquals( $expected, $result );
257+
} elseif ( PDO::FETCH_NAMED === $mode ) {
258+
// PDO::FETCH_NAMED returns all array keys as strings, even numeric
259+
// ones. This is not possible in plain PHP and might be a PDO bug.
260+
$this->assertSame( array_map( 'strval', array_keys( $expected ) ), array_keys( $result ) );
261+
$this->assertSame( array_values( $expected ), array_values( $result ) );
252262
} else {
253263
$this->assertSame( $expected, $result );
254264
}

0 commit comments

Comments
 (0)