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();
122 (
new ReflectionClass(\
ILIAS\
Test\TestDIC::class))
123 ->getProperty(
'dic')->setValue(
null,
null);
126 public static function callMethod($obj, $name, array $args = [])
128 return (
new ReflectionClass($obj))->getMethod($name)->invokeArgs($obj, $args);
133 $reflection_class =
new ReflectionClass($obj);
135 while ($reflection_class !==
false && !$reflection_class->hasProperty($name)) {
136 $reflection_class = $reflection_class->getParentClass();
139 return $reflection_class
140 ? $reflection_class->getProperty($name)->getValue($obj)
141 :
throw new ReflectionException(
'Property not found.');
146 $constructor = (
new ReflectionClass($class_name))->getConstructor();
148 if ($constructor ===
null) {
149 return new $class_name();
154 foreach ($constructor->getParameters() as $constructor_parameter) {
155 $constructor_parameter_name = $constructor_parameter->getName();
157 if (isset($explicit_parameters[$constructor_parameter_name])) {
158 $parameters[$constructor_parameter_name] = $explicit_parameters[$constructor_parameter_name];
162 if ($constructor_parameter->isDefaultValueAvailable()) {
163 $parameters[$constructor_parameter_name] = $constructor_parameter->getDefaultValue();
167 if (!$constructor_parameter->hasType()) {
168 throw new Exception(
'Constructor parameter has no type.');
171 $constructor_parameter_type_name = $constructor_parameter->getType()?->getName();
172 $parameters[$constructor_parameter_name] = match ($constructor_parameter_type_name) {
176 'bool',
'true' =>
true,
179 'null',
'resource' =>
null,
180 'Closure' => (
static fn() =>
null),
181 'object' => (
object) [],
182 default => (
function ($constructor_parameter_type_name) {
183 if (enum_exists($constructor_parameter_type_name)) {
184 $enum_cases = $constructor_parameter_type_name::cases();
185 return array_shift($enum_cases);
189 })($constructor_parameter_type_name)
193 return new $class_name(...$parameters);
198 if (trait_exists($class_name)) {
200 eval(
"class $dynamic_class_name{use $class_name;}");
207 private function getOrCreateMock(
string $parameter_type): PHPUnit\Framework\MockObject\MockObject
209 if (isset($this->services[$parameter_type])) {
211 if (!isset(
$DIC[$this->services[$parameter_type]])) {
212 $DIC[$this->services[$parameter_type]] = $this->createMock($parameter_type);
215 return $DIC[$this->services[$parameter_type]];
218 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.