lochmueller /
language_detection
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Lochmueller\LanguageDetection\Tests\Unit; |
||
| 6 | |||
| 7 | use TYPO3\CMS\Core\Http\Client\GuzzleClientFactory; |
||
| 8 | use TYPO3\CMS\Core\Http\RequestFactory; |
||
| 9 | use TYPO3\CMS\Core\Information\Typo3Version; |
||
| 10 | use TYPO3\TestingFramework\Core\Unit\UnitTestCase; |
||
| 11 | |||
| 12 | abstract class AbstractUnitTest extends UnitTestCase |
||
| 13 | { |
||
| 14 | public static function assertExecutionTimeLessThenOrEqual(float $timeInSeconds, callable $workload): void |
||
| 15 | { |
||
| 16 | $beforeTime = microtime(true); |
||
| 17 | $workload(); |
||
| 18 | $timeUsage = microtime(true) - $beforeTime; |
||
| 19 | |||
| 20 | self::assertLessThanOrEqual($timeInSeconds, $timeUsage, 'Execution time of this workload should be less then ' . $timeInSeconds . ' seconds.'); |
||
| 21 | } |
||
| 22 | |||
| 23 | public static function assertExecutionMemoryLessThenOrEqual(float $memoryInKb, callable $workload): void |
||
| 24 | { |
||
| 25 | $beforeMemory = memory_get_usage(); |
||
| 26 | $workload(); |
||
| 27 | $memoryUsage = memory_get_usage() - $beforeMemory; |
||
| 28 | self::assertLessThanOrEqual(1024 * $memoryInKb, $memoryUsage, 'Execution memory of this workload should be less then ' . $memoryInKb . 'KB.'); |
||
| 29 | } |
||
| 30 | |||
| 31 | public function getRequestFactory(): RequestFactory |
||
| 32 | { |
||
| 33 | if ((new Typo3Version())->getMajorVersion() >= 12) { |
||
| 34 | return new RequestFactory(new GuzzleClientFactory()); |
||
|
0 ignored issues
–
show
|
|||
| 35 | } |
||
| 36 | return new RequestFactory(); |
||
| 37 | } |
||
| 38 | } |
||
| 39 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.