Skip to content

Commit f9092f1

Browse files
cedric-annetrasher
authored andcommitted
Enhance callPrivateConstructor() test helper method
1 parent 0c60f74 commit f9092f1

File tree

2 files changed

+5
-24
lines changed

2 files changed

+5
-24
lines changed

phpunit/GLPITestCase.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,13 @@ protected function callPrivateMethod($instance, string $methodName, ...$args)
191191
/**
192192
* Call a private constructor, and get the created instance.
193193
*
194-
* @param string $classname Class to instanciate
195-
* @param mixed $arg Constructor arguments
194+
* @template T
195+
* @param class-string<T> $classname Class to instanciate
196+
* @param array $args Constructor arguments
196197
*
197-
* @return mixed
198+
* @return T
198199
*/
199-
protected function callPrivateConstructor($classname, $args)
200+
protected function callPrivateConstructor(string $classname, array $args = [])
200201
{
201202
$class = new ReflectionClass($classname);
202203
$instance = $class->newInstanceWithoutConstructor();

tests/GLPITestCase.php

-20
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,6 @@ protected function callPrivateMethod($instance, string $methodName, ...$args)
148148
return $method->invoke($instance, ...$args);
149149
}
150150

151-
/**
152-
* Call a private constructor, and get the created instance.
153-
*
154-
* @param string $classname Class to instanciate
155-
* @param mixed $arg Constructor arguments
156-
*
157-
* @return mixed
158-
*/
159-
protected function callPrivateConstructor($classname, $args)
160-
{
161-
$class = new ReflectionClass($classname);
162-
$instance = $class->newInstanceWithoutConstructor();
163-
164-
$constructor = $class->getConstructor();
165-
$constructor->setAccessible(true);
166-
$constructor->invokeArgs($instance, $args);
167-
168-
return $instance;
169-
}
170-
171151
protected function resetSession()
172152
{
173153
Session::destroy();

0 commit comments

Comments
 (0)