Passed
Push — main ( b4ea3d...ecbac5 )
by Tim
13:33
created

assertExecutionTimeLessThenOrEqual()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lochmueller\LanguageDetection\Tests\Unit;
6
7
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
8
9
abstract class AbstractUnitTest extends UnitTestCase
10
{
11
    public static function assertExecutionTimeLessThenOrEqual(float $timeInSeconds, callable $workload): void
12
    {
13
        $beforeTime = microtime(true);
14
        $workload();
15
        $timeUsage = microtime(true) - $beforeTime;
16
17
        self::assertLessThanOrEqual($timeInSeconds, $timeUsage, 'Execution time of this workload should be less then ' . $timeInSeconds . ' seconds.');
18
    }
19
20
    public static function assertExecutionMemoryLessThenOrEqual(float $memoryInKb, callable $workload): void
21
    {
22
        $beforeMemory = memory_get_usage();
23
        $workload();
24
        $memoryUsage = memory_get_usage() - $beforeMemory;
25
        self::assertLessThanOrEqual(1024 * $memoryInKb, $memoryUsage, 'Execution memory of this workload should be less then ' . $memoryInKb . 'KB.');
26
    }
27
}
28