Completed
Pull Request — master (#476)
by Bruno
14:24
created

SQLLoggerCollectorTest::testCollect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace DoctrineORMModuleTest\Collector;
21
22
use PHPUnit_Framework_TestCase as TestCase;
23
use DoctrineORMModule\Collector\SQLLoggerCollector;
24
use Doctrine\DBAL\Logging\DebugStack;
25
use Zend\Mvc\MvcEvent;
26
27
class SQLLoggerCollectorTest extends TestCase
28
{
29
    /**
30
     * @var DebugStack
31
     */
32
    protected $logger;
33
34
    /**
35
     * @var string
36
     */
37
    protected $name = 'test-collector-name';
38
39
    /**
40
     * @var SQLLoggerCollector
41
     */
42
    protected $collector;
43
44
    public function setUp()
45
    {
46
        parent::setUp();
47
        $this->logger = new DebugStack();
48
        $this->collector = new SQLLoggerCollector($this->logger, $this->name);
49
    }
50
51
    public function testHasCorrectName()
52
    {
53
        $this->assertSame($this->name, $this->collector->getName());
54
    }
55
56
    public function testGetPriority()
57
    {
58
        $this->assertInternalType('int', $this->collector->getPriority());
59
    }
60
61
    public function testCollect()
62
    {
63
        $this->collector->collect(new MvcEvent());
64
    }
65
66
    public function testCanHide()
67
    {
68
        $this->assertTrue($this->collector->canHide());
69
        $this->logger->startQuery('some sql');
70
        $this->assertFalse($this->collector->canHide());
71
    }
72
73
    public function testGetQueryCount()
74
    {
75
        $this->assertSame(0, $this->collector->getQueryCount());
76
        $this->logger->startQuery('some sql');
77
        $this->assertSame(1, $this->collector->getQueryCount());
78
        $this->logger->startQuery('some more sql');
79
        $this->assertSame(2, $this->collector->getQueryCount());
80
    }
81
82
    public function testGetQueryTime()
83
    {
84
        $start = microtime(true);
85
        $this->assertEquals(0, $this->collector->getQueryTime());
86
87
        $this->logger->startQuery('some sql');
88
        $this->logger->stopQuery();
89
        $time = microtime(true) - $start;
90
        $time1 = $this->collector->getQueryTime();
91
        $this->assertGreaterThan(0, $time1);
92
        $this->assertLessThan($time, $time1);
93
94
        $this->logger->startQuery('some more sql');
95
        $this->logger->stopQuery();
96
        $time = microtime(true) - $start;
97
        $time2 = $this->collector->getQueryTime();
98
        $this->assertGreaterThan($time1, $time2);
99
        $this->assertLessThan($time, $time1);
100
    }
101
}
102