Created
November 16, 2021 07:24
-
-
Save dima731515/2d8c25c7e5362b870005a17140d2396e to your computer and use it in GitHub Desktop.
Тестирование закрытых методов
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
/** | |
* Для тестирования Закрытых методов | |
* Для метода: "$res = СlinicTable::validateInnKpp(123123, 123123);" Использовать в тесте: | |
* $res = $this->runProtectedMethod(ClinicTable::class, 'validateInnKpp', [123123, 123123]); | |
* | |
* @throws ReflectionException | |
* | |
*/ | |
protected static function runProtectedMethod($objectOrClass, string $methodName, array $args = []) | |
{ | |
$refClass = new ReflectionClass($objectOrClass); | |
$method = $refClass->getMethod($methodName); | |
$method->setAccessible(true); | |
$object = (is_object($objectOrClass)) ? (new $objectOrClass) : null; | |
return $method->invokeArgs($object, $args); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment