elektronika_bagisto/tests/_support/UnitTester.php

77 lines
2.0 KiB
PHP
Raw Normal View History

2019-11-23 22:05:38 +00:00
<?php
2020-02-04 10:18:40 +00:00
use Codeception\Stub;
2019-11-23 22:05:38 +00:00
/**
* Inherited methods.
*
2019-11-23 22:05:38 +00:00
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause()
*
* @SuppressWarnings(PHPMD)
2020-02-04 10:18:40 +00:00
*/
2019-11-23 22:05:38 +00:00
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
2020-02-04 10:18:40 +00:00
/**
* Execute any function of a class (also private/protected) and return its return.
2020-02-04 10:18:40 +00:00
*
* @param string|object $className
* @param string $functionName
* @param array $methodParams
* @param array $constructParams
* @param array $mocks
2020-02-04 10:18:40 +00:00
* @return mixed
*
2020-02-04 10:18:40 +00:00
* @throws \Exception
*/
public function executeFunction(
$className,
string $functionName,
array $methodParams = [],
array $constructParams = [],
array $mocks = []
) {
$I = $this;
$I->comment(
'I execute function "'
2020-02-04 10:18:40 +00:00
. $functionName
. '" of class "'
. (is_object($className) ? get_class($className) : $className)
. '" with '
. count($methodParams)
. ' method-params, '
. count($constructParams)
. ' constuctor-params and '
. count($mocks)
. ' mocked class-methods/params'
);
2020-02-04 10:18:40 +00:00
$class = new \ReflectionClass($className);
2020-02-04 10:18:40 +00:00
$method = $class->getMethod($functionName);
2020-02-04 10:18:40 +00:00
$method->setAccessible(true);
2020-02-04 10:18:40 +00:00
if (is_object($className)) {
$reflectedClass = $className;
} elseif (empty($constructParams)) {
$reflectedClass = Stub::make($className, $mocks);
} else {
$reflectedClass = Stub::construct($className, $constructParams, $mocks);
}
return $method->invokeArgs($reflectedClass, $methodParams);
}
2019-11-23 22:05:38 +00:00
}