19declare(strict_types=1);
21require_once __DIR__ .
'/ilTestBaseTestCaseTrait.php';
23use PHPUnit\Framework\TestCase;
43 protected function setUp(): void
45 error_reporting(E_ALL);
51 $DIC = $this->getMockBuilder(Container::class)->onlyMethods([])->getMock();
123 (
new ReflectionClass(\
ILIAS\
Test\TestDIC::class))
124 ->getProperty(
'dic')->setValue(
null,
null);
127 public static function callMethod($obj, $name, array $args = [])
129 return (
new ReflectionClass($obj))->getMethod($name)->invokeArgs($obj, $args);
134 $reflection_class =
new ReflectionClass($obj);
136 while ($reflection_class !==
false && !$reflection_class->hasProperty($name)) {
137 $reflection_class = $reflection_class->getParentClass();
140 return $reflection_class
141 ? $reflection_class->getProperty($name)->getValue($obj)
142 :
throw new ReflectionException(
'Property not found.');
147 $constructor = (
new ReflectionClass($class_name))->getConstructor();
149 if ($constructor ===
null) {
150 return new $class_name();
155 foreach ($constructor->getParameters() as $constructor_parameter) {
156 $constructor_parameter_name = $constructor_parameter->getName();
158 if (isset($explicit_parameters[$constructor_parameter_name])) {
159 $parameters[$constructor_parameter_name] = $explicit_parameters[$constructor_parameter_name];
163 if ($constructor_parameter->isDefaultValueAvailable()) {
164 $parameters[$constructor_parameter_name] = $constructor_parameter->getDefaultValue();
168 if (!$constructor_parameter->hasType()) {
169 throw new Exception(
'Constructor parameter has no type.');
172 $constructor_parameter_type_name = $constructor_parameter->getType()?->getName();
173 $parameters[$constructor_parameter_name] = match ($constructor_parameter_type_name) {
177 'bool',
'true' =>
true,
180 'null',
'resource' =>
null,
181 'Closure' => (
static fn() =>
null),
182 'object' => (
object) [],
183 default => (
function ($constructor_parameter_type_name) {
184 if (enum_exists($constructor_parameter_type_name)) {
185 $enum_cases = $constructor_parameter_type_name::cases();
186 return array_shift($enum_cases);
190 })($constructor_parameter_type_name)
194 return new $class_name(...$parameters);
199 if (trait_exists($class_name)) {
201 eval(
"class $dynamic_class_name{use $class_name;}");
208 private function getOrCreateMock(
string $parameter_type): PHPUnit\Framework\MockObject\MockObject
210 if (isset($this->services[$parameter_type])) {
212 if (!isset(
$DIC[$this->services[$parameter_type]])) {
213 $DIC[$this->services[$parameter_type]] = $this->createMock($parameter_type);
216 return $DIC[$this->services[$parameter_type]];
219 return $this->createMock($parameter_type);
Customizing of pimple-DIC for ILIAS.
createTraitInstanceOf(string $class_name, array $explicit_parameters=[])
const string DYNAMIC_CLASS
static int $DYNAMIC_CLASS_COUNT
createInstanceOf(string $class_name, array $explicit_parameters=[])
static getNonPublicPropertyValue(object $obj, string $name)
getOrCreateMock(string $parameter_type)
const string MOCKED_METHOD_WITHOUT_OUTPUT
static callMethod($obj, $name, array $args=[])
addGlobal_objDefinition()
addGlobal_ilAppEventHandler()
addGlobal_ilNavigationHistory()
addGlobal_ilComponentFactory()
addGlobal_GlobalScreenService()
addGlobal_objectMetadata()
addGlobal_ilObjDataCache()
addGlobal_resourceStorage()
addGlobal_ilComponentRepository()
addGlobal_ilLoggerFactory()
trait ilTestBaseTestCaseTrait
addGlobal_objectService()
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.