DbalPerformanceTestCase.php 1.29 KB
Newer Older
1 2 3
<?php

namespace Doctrine\Tests;
4
use function microtime;
5 6

/**
7 8 9 10 11 12
 * 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.
 *
13 14 15 16 17 18
 * @package Doctrine\Tests\DBAL
 * @author Bill Schaller
 */
class DbalPerformanceTestCase extends DbalFunctionalTestCase
{
    /**
19 20 21
     * time the test started
     *
     * @var float
22
     */
23
    private $startTime;
24 25

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

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

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

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

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