DbalPerformanceTestCase.php 1.27 KB
Newer Older
1 2 3 4 5
<?php

namespace Doctrine\Tests;

/**
6 7 8 9 10 11
 * Base class for all DBAL performance tests.
 * 
 * Tests implemented in this class must call startTiming at the beginning
 * and stopTiming at the end of all tests. Tests that do not start or stop
 * timing will fail.
 *
12 13 14 15 16 17
 * @package Doctrine\Tests\DBAL
 * @author Bill Schaller
 */
class DbalPerformanceTestCase extends DbalFunctionalTestCase
{
    /**
18 19 20
     * time the test started
     *
     * @var float
21
     */
22
    private $startTime;
23 24

    /**
25 26 27
     * elapsed run time of the last test
     *
     * @var float
28
     */
29
    private $runTime;
30 31

    /**
32 33 34 35 36
     * {@inheritdoc}
     */
    protected function assertPostConditions()
    {
        // If a perf test doesn't start or stop, it fails.
37 38
        self::assertNotNull($this->startTime, "Test timing was started");
        self::assertNotNull($this->runTime, "Test timing was stopped");
39 40 41 42 43 44 45 46 47 48 49 50
    }

    /**
     * begin timing
     */
    protected function startTiming()
    {
        $this->startTime = microtime(true);
    }

    /**
     * end timing
51
     */
52
    protected function stopTiming()
53
    {
54
        $this->runTime = microtime(true) - $this->startTime;
55 56 57
    }

    /**
58
     * @return float elapsed test execution time
59
     */
60
    public function getTime()
61
    {
62
        return $this->runTime;
63 64
    }
}