Commit 3cf559fc authored by Benjamin Eberlei's avatar Benjamin Eberlei

Port functional test failure routines from ORM to DBAL testsuite

parent 833a3f94
......@@ -51,7 +51,11 @@ class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_conn->commit();
$this->_conn->beginTransaction();
try {
$this->_conn->insert("nontemporary", array("id" => 1));
} catch(Exception $e) {
$this->fail("Error: " . $e->getMessage() . " --- Existing tables: " . implode(", ", $this->_conn->getSchemaManager()->listTableNames()));
}
$this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable));
......
......@@ -16,6 +16,11 @@ class DbalFunctionalTestCase extends DbalTestCase
*/
protected $_conn;
/**
* @var \Doctrine\DBAL\Logging\DebugStack
*/
protected $_sqlLoggerStack;
protected function resetSharedConn()
{
if (self::$_sharedConn) {
......@@ -30,5 +35,42 @@ class DbalFunctionalTestCase extends DbalTestCase
self::$_sharedConn = TestUtil::getConnection();
}
$this->_conn = self::$_sharedConn;
$this->_sqlLoggerStack = new \Doctrine\DBAL\Logging\DebugStack();
$this->_conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack);
}
protected function onNotSuccessfulTest(\Exception $e)
{
if ($e instanceof \PHPUnit_Framework_AssertionFailedError) {
throw $e;
}
if(isset($this->_sqlLoggerStack->queries) && count($this->_sqlLoggerStack->queries)) {
$queries = "";
for($i = count($this->_sqlLoggerStack->queries)-1; $i > max(count($this->_sqlLoggerStack->queries)-25, 0) && isset($this->_sqlLoggerStack->queries[$i]); $i--) {
$query = $this->_sqlLoggerStack->queries[$i];
$params = array_map(function($p) { if (is_object($p)) return get_class($p); else return "'".$p."'"; }, $query['params'] ?: array());
$queries .= ($i+1).". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL;
}
$trace = $e->getTrace();
$traceMsg = "";
foreach($trace AS $part) {
if(isset($part['file'])) {
if(strpos($part['file'], "PHPUnit/") !== false) {
// Beginning with PHPUnit files we don't print the trace anymore.
break;
}
$traceMsg .= $part['file'].":".$part['line'].PHP_EOL;
}
}
$message = "[".get_class($e)."] ".$e->getMessage().PHP_EOL.PHP_EOL."With queries:".PHP_EOL.$queries.PHP_EOL."Trace:".PHP_EOL.$traceMsg;
throw new \Exception($message, (int)$e->getCode(), $e);
}
throw $e;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment