Failed Conditions
Push — master ( ff1501...ac0e13 )
by Sergei
22s queued 17s
created

tests/PerformanceTestListener.php (2 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\DBAL\Tests;
6
7
use PHPUnit\Framework\Test;
8
use PHPUnit\Framework\TestListener;
9
use PHPUnit\Framework\TestListenerDefaultImplementation;
10
use function get_class;
11
use function printf;
12
use function str_replace;
13
14
/**
15
 * Listener for collecting and reporting results of performance tests
16
 */
17
class PerformanceTestListener implements TestListener
0 ignored issues
show
Deprecated Code introduced by
The interface PHPUnit\Framework\TestListener has been deprecated: Use the `TestHook` interfaces instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

17
class PerformanceTestListener implements /** @scrutinizer ignore-deprecated */ TestListener

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
18
{
19
    use TestListenerDefaultImplementation;
0 ignored issues
show
Deprecated Code introduced by
The trait PHPUnit\Framework\TestLi...erDefaultImplementation has been deprecated: The `TestListener` interface is deprecated ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

19
    use /** @scrutinizer ignore-deprecated */ TestListenerDefaultImplementation;

This trait has been deprecated. The supplier of the trait has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the trait will be removed and what other trait to use instead.

Loading history...
20
21
    /** @var string[][] */
22
    private $timings = [];
23
24
    public function endTest(Test $test, float $time) : void
25
    {
26
        // This listener only applies to performance tests.
27
        if (! ($test instanceof PerformanceTestCase)) {
28
            return;
29
        }
30
31
        // we identify perf tests by class, method, and dataset
32
        $class = str_replace('\\Doctrine\\Tests\\DBAL\\Performance\\', '', get_class($test));
33
34
        if (! isset($this->timings[$class])) {
35
            $this->timings[$class] = [];
36
        }
37
38
        // Store timing data for each test in the order they were run.
39
        $this->timings[$class][$test->getName(true)] = $test->getTime();
40
    }
41
42
    /**
43
     * Report performance test timings.
44
     *
45
     * Note: __destruct is used here because PHPUnit doesn't have a
46
     * 'All tests over' hook.
47
     */
48
    public function __destruct()
49
    {
50
        if (empty($this->timings)) {
51
            return;
52
        }
53
54
        // Report timings.
55
        print "\nPerformance test results:\n\n";
56
57
        foreach ($this->timings as $class => $tests) {
58
            printf("%s:\n", $class);
59
            foreach ($tests as $test => $time) {
60
                printf("\t%s: %.3f seconds\n", $test, $time);
61
            }
62
        }
63
    }
64
}
65