Fix DatabaseSqlite::__toString
authorMarius Hoch <hoo@online.de>
Mon, 5 Oct 2015 20:42:28 +0000 (22:42 +0200)
committerMaxSem <maxsem.wiki@gmail.com>
Mon, 5 Oct 2015 20:54:11 +0000 (20:54 +0000)
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
tests/phpunit/includes/db/DatabaseSqliteTest.php

index e909597..dd65042 100644 (file)
@@ -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
 
 /**
index 9307b0c..0db7af9 100644 (file)
@@ -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 );
+       }
 }