Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable DebugStack logger in the test suite #4680

Merged
merged 1 commit into from Jun 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
}