Skip to content

Commit

Permalink
Merge pull request #4680 from morozov/disable-debug-stack-logger
Browse files Browse the repository at this point in the history
Disable DebugStack logger in the test suite
  • Loading branch information
morozov committed Jun 18, 2021
2 parents e817657 + 308a152 commit 4c1a55f
Showing 1 changed file with 0 additions and 78 deletions.
78 changes: 0 additions & 78 deletions tests/FunctionalTestCase.php
Expand Up @@ -3,23 +3,7 @@
namespace Doctrine\DBAL\Tests;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Logging\DebugStack;
use Exception;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\TestCase;
use Throwable;

use function array_map;
use function array_reverse;
use function count;
use function get_class;
use function implode;
use function is_object;
use function is_scalar;
use function strpos;
use function var_export;

use const PHP_EOL;

abstract class FunctionalTestCase extends TestCase
{
Expand All @@ -33,9 +17,6 @@ abstract class FunctionalTestCase extends TestCase
/** @var Connection */
protected $connection;

/** @var DebugStack|null */
protected $sqlLoggerStack;

/**
* Whether the shared connection could be reused by subsequent tests.
*
Expand All @@ -56,15 +37,11 @@ protected function markConnectionNotReusable(): void

protected function setUp(): void
{
$this->sqlLoggerStack = new DebugStack();

if (self::$sharedConnection === null) {
self::$sharedConnection = TestUtil::getConnection();
}

$this->connection = self::$sharedConnection;

$this->connection->getConfiguration()->setSQLLogger($this->sqlLoggerStack);
}

protected function tearDown(): void
Expand All @@ -91,59 +68,4 @@ protected function tearDown(): void

$this->isConnectionReusable = true;
}

protected function onNotSuccessfulTest(Throwable $t): void
{
if ($t instanceof AssertionFailedError) {
throw $t;
}

if ($this->sqlLoggerStack !== null && count($this->sqlLoggerStack->queries) > 0) {
$queries = '';
$i = count($this->sqlLoggerStack->queries);
foreach (array_reverse($this->sqlLoggerStack->queries) as $query) {
$params = array_map(
/**
* @param mixed $p
*/
static function ($p): string {
if (is_object($p)) {
return get_class($p);
}

if (is_scalar($p)) {
return "'" . $p . "'";
}

return var_export($p, true);
},
$query['params'] ?? []
);
$queries .= $i . ". SQL: '" . $query['sql'] . "' Params: " . implode(', ', $params) . PHP_EOL;
$i--;
}

$trace = $t->getTrace();
$traceMsg = '';
foreach ($trace as $part) {
if (! isset($part['file'])) {
continue;
}

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($t) . '] ' . $t->getMessage() . PHP_EOL . PHP_EOL
. 'With queries:' . PHP_EOL . $queries . PHP_EOL . 'Trace:' . PHP_EOL . $traceMsg;

throw new Exception($message, (int) $t->getCode(), $t);
}

throw $t;
}
}

0 comments on commit 4c1a55f

Please sign in to comment.