class Document extends AbstractClass
{
public function handle($params)
{
$requestBody = 'body';
return $this->request($requestBody);
}
}
abstract class AbstractClass
{
protected function request($body)
{
}
}
$class = new ReflectionClass(AbstractClass::class);
$method = $class->getMethod('request');
$method->setAccessible(true);
$document = new Document();
$result = $method->invoke($document,$params);
abstract class AbstractClass
{
protected function request($body)
{
return Document::TEST_VALUE;
}
}
class Document extends AbstractClass
{
const TEST_VALUE = 403;
public function handle($params)
{
$requestBody = 'body';
return $this->request($requestBody);
}
}
class DocumentTest
{
public function testRequest()
{
$doc = new Document();
$result = $this->invokeMethod($doc, 'request', [1]);
self::assertEquals(Document::TEST_VALUE, $result);
}
private function invokeMethod(&$object, $methodName, array $parameters = array())
{
$reflection = new \ReflectionClass(get_class($object));
$method = $reflection->getMethod($methodName);
$method->setAccessible(true);
return $method->invokeArgs($object, $parameters);
}
}