DebugStackTest.php 1.15 KB
Newer Older
1 2 3 4 5 6
<?php

namespace Doctrine\Tests\DBAL\Logging;

class DebugStackTest extends \Doctrine\Tests\DbalTestCase
{
7
    protected function setUp()
8 9 10 11
    {
        $this->logger = new \Doctrine\DBAL\Logging\DebugStack();
    }

12
    protected function tearDown()
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
    {
        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);
    }
}