Added list of SQL statement to debug output

This commit is contained in:
Marcin Kurczewski 2014-10-05 20:25:11 +02:00
parent 6bf8586735
commit 640b66a324
4 changed files with 20 additions and 3 deletions

View file

@ -76,3 +76,4 @@ postsPerPage = 40
[misc] [misc]
thumbnailCropStyle = outside thumbnailCropStyle = outside
customFaviconUrl = /favicon.png customFaviconUrl = /favicon.png
dumpSqlIntoQueries = 0

View file

@ -4,12 +4,14 @@ namespace Szurubooru;
final class Dispatcher final class Dispatcher
{ {
private $router; private $router;
private $config;
private $databaseConnection; private $databaseConnection;
private $authService; private $authService;
private $tokenService; private $tokenService;
public function __construct( public function __construct(
\Szurubooru\Router $router, \Szurubooru\Router $router,
\Szurubooru\Config $config,
\Szurubooru\DatabaseConnection $databaseConnection, \Szurubooru\DatabaseConnection $databaseConnection,
\Szurubooru\Helpers\HttpHelper $httpHelper, \Szurubooru\Helpers\HttpHelper $httpHelper,
\Szurubooru\Services\AuthService $authService, \Szurubooru\Services\AuthService $authService,
@ -17,6 +19,7 @@ final class Dispatcher
\Szurubooru\ControllerRepository $controllerRepository) \Szurubooru\ControllerRepository $controllerRepository)
{ {
$this->router = $router; $this->router = $router;
$this->config = $config;
$this->databaseConnection = $databaseConnection; $this->databaseConnection = $databaseConnection;
$this->httpHelper = $httpHelper; $this->httpHelper = $httpHelper;
@ -50,7 +53,11 @@ final class Dispatcher
} }
$end = microtime(true); $end = microtime(true);
$json['__time'] = $end - \Szurubooru\Bootstrap::getStartTime(); $json['__time'] = $end - \Szurubooru\Bootstrap::getStartTime();
$json['__queries'] = $this->databaseConnection->getPDO()->getQueryCount(); if ($this->config->misc->dumpSqlIntoQueries)
{
$json['__queries'] = $this->databaseConnection->getPDO()->getQueryCount();
$json['__statements'] = $this->databaseConnection->getPDO()->getStatements();
}
$this->httpHelper->setResponseCode($code); $this->httpHelper->setResponseCode($code);
$this->httpHelper->setHeader('Content-Type', 'application/json'); $this->httpHelper->setHeader('Content-Type', 'application/json');

View file

@ -4,10 +4,12 @@ namespace Szurubooru;
class PDOEx extends \PDO class PDOEx extends \PDO
{ {
private $queryCount = 0; private $queryCount = 0;
private $statements = [];
public function prepare($statement, $driverOptions = []) public function prepare($statement, $driverOptions = [])
{ {
++ $this->queryCount; ++ $this->queryCount;
$this->statements[] = $statement;
return parent::prepare($statement, $driverOptions); return parent::prepare($statement, $driverOptions);
} }
@ -15,4 +17,9 @@ class PDOEx extends \PDO
{ {
return $this->queryCount; return $this->queryCount;
} }
public function getStatements()
{
return $this->statements;
}
} }

View file

@ -4,6 +4,7 @@ namespace Szurubooru\Tests;
final class DispatcherTest extends \Szurubooru\Tests\AbstractDatabaseTestCase final class DispatcherTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
{ {
private $routerMock; private $routerMock;
private $configMock;
private $httpHelperMock; private $httpHelperMock;
private $authServiceMock; private $authServiceMock;
private $tokenServiceMock; private $tokenServiceMock;
@ -13,10 +14,12 @@ final class DispatcherTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
{ {
parent::setUp(); parent::setUp();
$this->routerMock = $this->mock(\Szurubooru\Router::class); $this->routerMock = $this->mock(\Szurubooru\Router::class);
$this->configMock = $this->mockConfig();
$this->httpHelperMock = $this->mock(\Szurubooru\Helpers\HttpHelper::class); $this->httpHelperMock = $this->mock(\Szurubooru\Helpers\HttpHelper::class);
$this->authServiceMock = $this->mock(\Szurubooru\Services\AuthService::class); $this->authServiceMock = $this->mock(\Szurubooru\Services\AuthService::class);
$this->tokenServiceMock = $this->mock(\Szurubooru\Services\TokenService::class); $this->tokenServiceMock = $this->mock(\Szurubooru\Services\TokenService::class);
$this->controllerRepositoryMock = $this->mock(\Szurubooru\ControllerRepository::class); $this->controllerRepositoryMock = $this->mock(\Szurubooru\ControllerRepository::class);
$this->configMock->set('misc/dumpSqlIntoQueries', 0);
} }
public function testDispatchingArrays() public function testDispatchingArrays()
@ -34,7 +37,6 @@ final class DispatcherTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
$actual = $dispatcher->run('GET', '/'); $actual = $dispatcher->run('GET', '/');
unset($actual['__time']); unset($actual['__time']);
unset($actual['__queries']);
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
@ -51,7 +53,6 @@ final class DispatcherTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
$actual = $dispatcher->run('GET', '/'); $actual = $dispatcher->run('GET', '/');
unset($actual['__time']); unset($actual['__time']);
unset($actual['__queries']);
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
@ -69,6 +70,7 @@ final class DispatcherTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
{ {
return new \Szurubooru\Dispatcher( return new \Szurubooru\Dispatcher(
$this->routerMock, $this->routerMock,
$this->configMock,
$this->databaseConnection, $this->databaseConnection,
$this->httpHelperMock, $this->httpHelperMock,
$this->authServiceMock, $this->authServiceMock,