linkmobility-php-client/Tests/ApiTestCase.php

61 regels
1.6 KiB
PHP

2022-07-09 22:16:46 +02:00
<?php
namespace D3\LinkmobilityClient\Tests;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionException;
abstract class ApiTestCase extends TestCase
{
/**
* Calls a private or protected object method.
*
* @param object $object
* @param string $methodName
* @param array $arguments
*
* @return mixed
* @throws ReflectionException
*/
2022-07-10 21:52:37 +02:00
public function callMethod(object $object, string $methodName, array $arguments = array())
2022-07-09 22:16:46 +02:00
{
$class = new ReflectionClass($object);
$method = $class->getMethod($methodName);
$method->setAccessible(true);
return $method->invokeArgs($object, $arguments);
}
/**
* Sets a private or protected property in defined class instance
*
* @param object $object
* @param string $valueName
* @param $value
* @throws ReflectionException
*/
public function setValue(object $object, string $valueName, $value)
{
$reflection = new ReflectionClass($object);
$property = $reflection->getProperty($valueName);
$property->setAccessible(true);
$property->setValue($object, $value);
}
/**
* get a private or protected property from defined class instance
*
* @param object $object
* @param string $valueName
* @return mixed
* @throws ReflectionException
*/
2022-07-10 21:52:37 +02:00
public function getValue(object $object, string $valueName)
2022-07-09 22:16:46 +02:00
{
$reflection = new ReflectionClass($object);
$property = $reflection->getProperty($valueName);
$property->setAccessible(true);
return $property->getValue($object);
}
}