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

DebugStack should ignore stopQuery when disabled #168

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/Doctrine/DBAL/Logging/DebugStack.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public function startQuery($sql, array $params = null, array $types = null)
*/ */
public function stopQuery() public function stopQuery()
{ {
$this->queries[$this->currentQuery]['executionMS'] = microtime(true) - $this->start; if ($this->enabled) {
$this->queries[$this->currentQuery]['executionMS'] = microtime(true) - $this->start;
}
} }
} }

47 changes: 47 additions & 0 deletions tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Doctrine\Tests\DBAL\Logging;

require_once __DIR__ . '/../../TestInit.php';

class DebugStackTest extends \Doctrine\Tests\DbalTestCase
{
public function setUp()
{
$this->logger = new \Doctrine\DBAL\Logging\DebugStack();
}

public function tearDown()
{
unset($this->logger);
}

public function testLoggedQuery()
{
$this->logger->startQuery('SELECT column FROM table');
$this->assertEquals(
array(
1 => array(
'sql' => 'SELECT column FROM table',
'params' => null,
'types' => null,
'executionMS' => 0,
),
),
$this->logger->queries
);

$this->logger->stopQuery();
$this->assertGreaterThan(0, $this->logger->queries[1]['executionMS']);
}

public function testLoggedQueryDisabled()
{
$this->logger->enabled = false;
$this->logger->startQuery('SELECT column FROM table');
$this->assertEquals(array(), $this->logger->queries);

$this->logger->stopQuery();
$this->assertEquals(array(), $this->logger->queries);
}
}