From 2c03cd32d04e8877fd2caf56d84dc28c44eb681a Mon Sep 17 00:00:00 2001 From: Marius Hoch Date: Mon, 5 Oct 2015 22:42:28 +0200 Subject: [PATCH] Fix DatabaseSqlite::__toString Failed with "Catchable fatal error: Object of class PDO could not be converted to string in". The message I used was a rather arbitrary choice, but I think it makes sense. Bug: T114709 Change-Id: I0023fae3fa2a0c2b37cb3c34751706fe0d481d19 --- includes/db/DatabaseSqlite.php | 8 ++++++++ tests/phpunit/includes/db/DatabaseSqliteTest.php | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index e9095970a7..dd65042be5 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -1032,6 +1032,14 @@ class DatabaseSqlite extends DatabaseBase { return $endArray; } + + /** + * @return string + */ + public function __toString() { + return 'SQLite ' . (string)$this->mConn->getAttribute( PDO::ATTR_SERVER_VERSION ); + } + } // end DatabaseSqlite class /** diff --git a/tests/phpunit/includes/db/DatabaseSqliteTest.php b/tests/phpunit/includes/db/DatabaseSqliteTest.php index 9307b0cda9..0db7af9392 100644 --- a/tests/phpunit/includes/db/DatabaseSqliteTest.php +++ b/tests/phpunit/includes/db/DatabaseSqliteTest.php @@ -482,4 +482,12 @@ class DatabaseSqliteTest extends MediaWikiTestCase { $this->assertTrue( $db->close(), "closing database" ); } + + public function testToString() { + $db = DatabaseSqlite::newStandaloneInstance( ':memory:' ); + + $toString = (string)$db; + + $this->assertContains( 'SQLite ', $toString ); + } } -- 2.20.1