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

namespace Doctrine\Tests;
Sergei Morozov's avatar
Sergei Morozov committed
4

5
use function microtime;
6 7

/**
8
 * Base class for all DBAL performance tests.
Sergei Morozov's avatar
Sergei Morozov committed
9
 *
10 11 12
 * 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
 */
class DbalPerformanceTestCase extends DbalFunctionalTestCase
{
    /**
17 18 19
     * time the test started
     *
     * @var float
20
     */
21
    private $startTime;
22 23

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

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

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

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

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