ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilTestBaseTestCase Class Reference

Class ilTestBaseClass. More...

+ Inheritance diagram for ilTestBaseTestCase:
+ Collaboration diagram for ilTestBaseTestCase:

Public Member Functions

 createInstanceOf (string $class_name, array $explicit_parameters=[])
 
 createTraitInstanceOf (string $class_name, array $explicit_parameters=[])
 

Static Public Member Functions

static callMethod ($obj, $name, array $args=[])
 
static getNonPublicPropertyValue (object $obj, string $name)
 

Data Fields

const string MOCKED_METHOD_WITHOUT_OUTPUT = 'MOCKED_METHOD_WITHOUT_OUTPUT'
 
const string DYNAMIC_CLASS = 'DynamicClass'
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 

Protected Attributes

Container $dic = null
 
Container $backup_dic = null
 

Static Protected Attributes

static int $DYNAMIC_CLASS_COUNT = 0
 

Private Member Functions

 addGlobals ()
 
 prepareLocalDIC ()
 
 getOrCreateMock (string $parameter_type)
 

Detailed Description

Class ilTestBaseClass.

Author
Marvin Beym mbeym.nosp@m.@dat.nosp@m.abay..nosp@m.de

Definition at line 30 of file ilTestBaseTestCase.php.

Member Function Documentation

◆ addGlobals()

ilTestBaseTestCase::addGlobals ( )
private

Definition at line 67 of file ilTestBaseTestCase.php.

References addGlobal_dataFactory(), addGlobal_fileDelivery(), addGlobal_filesystem(), addGlobal_GlobalScreenService(), addGlobal_http(), addGlobal_ilAccess(), addGlobal_ilAppEventHandler(), addGlobal_ilBench(), addGlobal_ilComponentFactory(), addGlobal_ilComponentRepository(), addGlobal_ilCtrl(), addGlobal_ilDB(), addGlobal_ilErr(), addGlobal_ilHelp(), addGlobal_ilias(), addGlobal_ilLocator(), addGlobal_ilLog(), addGlobal_ilLoggerFactory(), addGlobal_ilNavigationHistory(), addGlobal_ilObjDataCache(), addGlobal_ilRbacAdmin(), addGlobal_ilSetting(), addGlobal_ilTabs(), addGlobal_ilToolbar(), addGlobal_ilUser(), addGlobal_lng(), addGlobal_objDefinition(), addGlobal_objectMetadata(), addGlobal_objectService(), addGlobal_rbacreview(), addGlobal_rbacsystem(), addGlobal_refinery(), addGlobal_resourceStorage(), addGlobal_static_url(), addGlobal_tpl(), addGlobal_tree(), addGlobal_uiFactory(), addGlobal_uiRenderer(), addGlobal_uiService(), addGlobal_upload(), defineGlobalConstants(), and prepareLocalDIC().

Referenced by setUp().

67  : void
68  {
69  $this->addGlobal_ilAccess();
70  $this->addGlobal_dataFactory();
71  $this->addGlobal_tpl();
72  $this->addGlobal_ilDB();
73  $this->addGlobal_ilUser();
74  $this->addGlobal_ilias();
75  $this->addGlobal_ilErr();
76  $this->addGlobal_tree();
77  $this->addGlobal_lng();
80  $this->addGlobal_objDefinition();
81  $this->addGlobal_refinery();
82  $this->addGlobal_rbacsystem();
83  $this->addGlobal_rbacreview();
84  $this->addGlobal_ilRbacAdmin();
85  $this->addGlobal_http();
86  $this->addGlobal_fileDelivery();
89  $this->addGlobal_uiFactory();
90  $this->addGlobal_uiRenderer();
91  $this->addGlobal_uiService();
92  $this->addGlobal_static_url();
93  $this->addGlobal_upload();
94  $this->addGlobal_ilLog();
95  $this->addGlobal_ilBench();
96  $this->addGlobal_ilSetting();
97  $this->addGlobal_ilCtrl();
98  $this->addGlobal_ilCtrl();
99  $this->addGlobal_ilObjDataCache();
100  $this->addGlobal_ilHelp();
101  $this->addGlobal_ilTabs();
102  $this->addGlobal_ilLocator();
103  $this->addGlobal_ilToolbar();
104  $this->addGlobal_filesystem();
105  $this->addGlobal_ilLoggerFactory();
108  $this->addGlobal_objectService();
109  $this->addGlobal_resourceStorage();
110  $this->addGlobal_objectMetadata();
111 
112  $this->defineGlobalConstants();
113 
114  $this->prepareLocalDIC();
115 
116  parent::setUp();
117  }
addGlobal_ilAppEventHandler()
addGlobal_ilComponentFactory()
addGlobal_filesystem()
addGlobal_rbacsystem()
addGlobal_objectService()
addGlobal_ilRbacAdmin()
addGlobal_rbacreview()
addGlobal_fileDelivery()
addGlobal_dataFactory()
addGlobal_resourceStorage()
addGlobal_ilLoggerFactory()
defineGlobalConstants()
addGlobal_ilNavigationHistory()
addGlobal_static_url()
addGlobal_objDefinition()
addGlobal_ilObjDataCache()
addGlobal_ilComponentRepository()
addGlobal_uiRenderer()
addGlobal_GlobalScreenService()
addGlobal_objectMetadata()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ callMethod()

static ilTestBaseTestCase::callMethod (   $obj,
  $name,
array  $args = [] 
)
static

Definition at line 125 of file ilTestBaseTestCase.php.

126  {
127  return (new ReflectionClass($obj))->getMethod($name)->invokeArgs($obj, $args);
128  }

◆ createInstanceOf()

ilTestBaseTestCase::createInstanceOf ( string  $class_name,
array  $explicit_parameters = [] 
)

Definition at line 143 of file ilTestBaseTestCase.php.

References getOrCreateMock(), and null.

Referenced by ILIAS\Test\Tests\Results\Data\TestResultRepositoryTest\createInstance(), and createTraitInstanceOf().

143  : object
144  {
145  $constructor = (new ReflectionClass($class_name))->getConstructor();
146 
147  if ($constructor === null) {
148  return new $class_name();
149  }
150 
151  $parameters = [];
152 
153  foreach ($constructor->getParameters() as $constructor_parameter) {
154  $constructor_parameter_name = $constructor_parameter->getName();
155 
156  if (isset($explicit_parameters[$constructor_parameter_name])) {
157  $parameters[$constructor_parameter_name] = $explicit_parameters[$constructor_parameter_name];
158  continue;
159  }
160 
161  if ($constructor_parameter->isDefaultValueAvailable()) {
162  $parameters[$constructor_parameter_name] = $constructor_parameter->getDefaultValue();
163  continue;
164  }
165 
166  if (!$constructor_parameter->hasType()) {
167  throw new Exception('Constructor parameter has no type.');
168  }
169 
170  $constructor_parameter_type_name = $constructor_parameter->getType()?->getName();
171  $parameters[$constructor_parameter_name] = match ($constructor_parameter_type_name) {
172  'string' => '',
173  'int' => 0,
174  'float' => 0.0,
175  'bool', 'true' => true,
176  'false' => false,
177  'array' => [],
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);
185  }
186 
187  return $this->getOrCreateMock($constructor_parameter_type_name);
188  })($constructor_parameter_type_name)
189  };
190  }
191 
192  return new $class_name(...$parameters);
193  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getOrCreateMock(string $parameter_type)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createTraitInstanceOf()

ilTestBaseTestCase::createTraitInstanceOf ( string  $class_name,
array  $explicit_parameters = [] 
)

Definition at line 195 of file ilTestBaseTestCase.php.

References createInstanceOf().

195  : object
196  {
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;}");
200  return $this->createInstanceOf($dynamic_class_name, $explicit_parameters);
201  }
202 
203  return $this->createInstanceOf($class_name, $explicit_parameters);
204  }
createInstanceOf(string $class_name, array $explicit_parameters=[])
+ Here is the call graph for this function:

◆ getNonPublicPropertyValue()

static ilTestBaseTestCase::getNonPublicPropertyValue ( object  $obj,
string  $name 
)
static

Definition at line 130 of file ilTestBaseTestCase.php.

130  : mixed
131  {
132  $reflection_class = new ReflectionClass($obj);
133 
134  while ($reflection_class !== false && !$reflection_class->hasProperty($name)) {
135  $reflection_class = $reflection_class->getParentClass();
136  }
137 
138  return $reflection_class
139  ? $reflection_class->getProperty($name)->getValue($obj)
140  : throw new ReflectionException('Property not found.');
141  }

◆ getOrCreateMock()

ilTestBaseTestCase::getOrCreateMock ( string  $parameter_type)
private

Definition at line 206 of file ilTestBaseTestCase.php.

References $DIC.

Referenced by createInstanceOf().

207  {
208  if (isset($this->services[$parameter_type])) {
209  global $DIC;
210  if (!isset($DIC[$this->services[$parameter_type]])) {
211  $DIC[$this->services[$parameter_type]] = $this->createMock($parameter_type);
212  }
213 
214  return $DIC[$this->services[$parameter_type]];
215  }
216 
217  return $this->createMock($parameter_type);
218  }
global $DIC
Definition: shib_login.php:26
+ Here is the caller graph for this function:

◆ prepareLocalDIC()

ilTestBaseTestCase::prepareLocalDIC ( )
private

Definition at line 119 of file ilTestBaseTestCase.php.

References null.

Referenced by addGlobals().

119  : void
120  {
121  (new ReflectionClass(\ILIAS\Test\TestDIC::class))
122  ->getProperty('dic')->setValue(null, null);
123  }
Interface Observer Contains several chained tasks and infos about them.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

◆ setUp()

ilTestBaseTestCase::setUp ( )
protected

Definition at line 43 of file ilTestBaseTestCase.php.

References $DIC, addGlobals(), and defineGlobalConstants().

43  : void
44  {
45  error_reporting(E_ALL);
46  $this->defineGlobalConstants();
47 
48  global $DIC;
49  $this->backup_dic = is_object($DIC) ? clone $DIC : $DIC;
50 
51  $DIC = $this->getMockBuilder(Container::class)->onlyMethods([])->getMock();
52  $this->addGlobals();
53  $this->dic = $DIC;
54 
55  parent::setUp();
56  }
global $DIC
Definition: shib_login.php:26
defineGlobalConstants()
+ Here is the call graph for this function:

◆ tearDown()

ilTestBaseTestCase::tearDown ( )
protected

Definition at line 58 of file ilTestBaseTestCase.php.

References $backup_dic, and $DIC.

58  : void
59  {
60  global $DIC;
61 
62  $DIC = $this->backup_dic;
63 
64  parent::tearDown();
65  }
global $DIC
Definition: shib_login.php:26

Field Documentation

◆ $backup_dic

Container ilTestBaseTestCase::$backup_dic = null
protected

Definition at line 38 of file ilTestBaseTestCase.php.

Referenced by tearDown().

◆ $dic

Container ilTestBaseTestCase::$dic = null
protected

Definition at line 37 of file ilTestBaseTestCase.php.

◆ $DYNAMIC_CLASS_COUNT

int ilTestBaseTestCase::$DYNAMIC_CLASS_COUNT = 0
staticprotected

Definition at line 36 of file ilTestBaseTestCase.php.

◆ DYNAMIC_CLASS

const string ilTestBaseTestCase::DYNAMIC_CLASS = 'DynamicClass'

Definition at line 35 of file ilTestBaseTestCase.php.

◆ MOCKED_METHOD_WITHOUT_OUTPUT

const string ilTestBaseTestCase::MOCKED_METHOD_WITHOUT_OUTPUT = 'MOCKED_METHOD_WITHOUT_OUTPUT'

Definition at line 34 of file ilTestBaseTestCase.php.


The documentation for this class was generated from the following file: