Index: DBTest.class.php =================================================================== --- DBTest.class.php (revision 7132) +++ DBTest.class.php (working copy) @@ -124,6 +124,20 @@ $this->conn->query('select 1'); // Not connected } + /** + * Test an SQLConnectionClosedException is thrown if the connection + * has been lost. + * + * @see rfc://0058 + * @access public + */ + #[@test, @expect('rdbms.SQLConnectionClosedException')] + function connectionLost() { + $this->conn->connect(); + $this->assertQuery(); + $this->conn->letServerDisconnect(); + $this->conn->query('select 1'); // Not connected + } /** * Test an SQLStateException is thrown if a query is performed on a Index: mock/MockConnection.class.php =================================================================== --- mock/MockConnection.class.php (revision 7133) +++ mock/MockConnection.class.php (working copy) @@ -67,6 +67,15 @@ } /** + * Mock: Let server disconnect. This will make query() thrown + * + * @access public + */ + function letServerDisconnect() { + $this->queryError= array(2013); + } + + /** * Mock: Make connect fail * * @access public @@ -326,14 +335,29 @@ if (FALSE === $c) return throw(new SQLStateException('Previously failed to connect.')); } - if (!empty($this->queryError)) { - $error= $this->queryError; - $this->queryError= array(); // Reset so next query succeeds again - return throw(new SQLStatementFailedException( - 'Statement failed: '.$error[1], - $sql, - $error[0] - )); + switch (sizeof($this->queryError)) { + case 0: { + return $this->resultSet; + } + + case 1: { // letServerDisconnect() sets this + $this->queryError= array(); + $this->_connected= FALSE; + return throw(new SQLConnectionClosedException( + 'Statement failed: Read from server failed', + $sql + )); + } + + case 2: { // makeQueryFail() sets this + $error= $this->queryError; + $this->queryError= array(); // Reset so next query succeeds again + return throw(new SQLStatementFailedException( + 'Statement failed: '.$error[1], + $sql, + $error[0] + )); + } } return $this->resultSet;