Skip to content

Instantly share code, notes, and snippets.

@dima731515
Created November 16, 2021 07:24
Show Gist options
  • Save dima731515/2d8c25c7e5362b870005a17140d2396e to your computer and use it in GitHub Desktop.
Save dima731515/2d8c25c7e5362b870005a17140d2396e to your computer and use it in GitHub Desktop.
Тестирование закрытых методов
<?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