19 declare(strict_types=1);
21 require_once __DIR__ .
'/ilTestBaseTestCaseTrait.php';
43 protected function setUp(): void
45 error_reporting(E_ALL);
49 $this->backup_dic = is_object($DIC) ? clone
$DIC :
$DIC;
51 $DIC = $this->getMockBuilder(Container::class)->onlyMethods([])->getMock();
122 ->getProperty(
'dic')->setValue(
null,
null);
125 public static function callMethod($obj, $name, array $args = [])
127 return (
new ReflectionClass($obj))->getMethod($name)->invokeArgs($obj, $args);
134 while ($reflection_class !==
false && !$reflection_class->hasProperty($name)) {
135 $reflection_class = $reflection_class->getParentClass();
138 return $reflection_class
139 ? $reflection_class->getProperty($name)->getValue($obj)
147 if ($constructor ===
null) {
148 return new $class_name();
153 foreach ($constructor->getParameters() as $constructor_parameter) {
154 $constructor_parameter_name = $constructor_parameter->getName();
156 if (isset($explicit_parameters[$constructor_parameter_name])) {
157 $parameters[$constructor_parameter_name] = $explicit_parameters[$constructor_parameter_name];
161 if ($constructor_parameter->isDefaultValueAvailable()) {
162 $parameters[$constructor_parameter_name] = $constructor_parameter->getDefaultValue();
166 if (!$constructor_parameter->hasType()) {
167 throw new Exception(
'Constructor parameter has no type.');
170 $constructor_parameter_type_name = $constructor_parameter->getType()?->getName();
171 $parameters[$constructor_parameter_name] = match ($constructor_parameter_type_name) {
175 'bool',
'true' =>
true,
178 'null',
'resource' =>
null,
179 'Closure' => (
static fn() =>
null),
180 'object' => (
object) [],
181 default => (
function ($constructor_parameter_type_name) {
182 if (enum_exists($constructor_parameter_type_name)) {
183 $enum_cases = $constructor_parameter_type_name::cases();
184 return array_shift($enum_cases);
188 })($constructor_parameter_type_name)
192 return new $class_name(...$parameters);
197 if (trait_exists($class_name)) {
198 $dynamic_class_name = self::DYNAMIC_CLASS . ++self::$DYNAMIC_CLASS_COUNT;
199 eval(
"class $dynamic_class_name{use $class_name;}");
208 if (isset($this->services[$parameter_type])) {
210 if (!isset($DIC[$this->services[$parameter_type]])) {
211 $DIC[$this->services[$parameter_type]] = $this->createMock($parameter_type);
214 return $DIC[$this->services[$parameter_type]];
217 return $this->createMock($parameter_type);
addGlobal_ilAppEventHandler()
addGlobal_ilComponentFactory()
createInstanceOf(string $class_name, array $explicit_parameters=[])
const string DYNAMIC_CLASS
static int $DYNAMIC_CLASS_COUNT
Interface Observer Contains several chained tasks and infos about them.
addGlobal_objectService()
static getNonPublicPropertyValue(object $obj, string $name)
Customizing of pimple-DIC for ILIAS.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getOrCreateMock(string $parameter_type)
static callMethod($obj, $name, array $args=[])
addGlobal_resourceStorage()
addGlobal_ilLoggerFactory()
addGlobal_ilNavigationHistory()
createTraitInstanceOf(string $class_name, array $explicit_parameters=[])
addGlobal_objDefinition()
addGlobal_ilObjDataCache()
addGlobal_ilComponentRepository()
trait ilTestBaseTestCaseTrait
addGlobal_GlobalScreenService()
const string MOCKED_METHOD_WITHOUT_OUTPUT
addGlobal_objectMetadata()