Behat / WebApiExtension

Behat extension to test web APIs
http://extensions.behat.org
MIT License
111 stars 114 forks source link

WebApiContext::$request and WebApiContext::$response should be protected not private #59

Open zippy1981 opened 8 years ago

zippy1981 commented 8 years ago

If I want to extend that context I need raw access to the request and response object.

kevin-lot commented 7 years ago

Take a look at this comment. https://github.com/Behat/WebApiExtension/issues/66#issuecomment-263845309

In fact, this repo needs to remove old version of Guzzle compatibility (the one that it doesn't use PSR-7) to change the visibility of this properties.

DanTalash commented 6 years ago

If you want to get access to the response object without forking this library you can always retrieve it via reflection.

For example, from a sub-class:

protected function getResponse() {
    static $propertyReflection;

    if ($propertyReflection === null) {
        $classReflection    = new ReflectionClass(WebApiContext::class);
        $propertyReflection = $classReflection->getProperty('response');

        $propertyReflection->setAccessible(true);
    }

    return $propertyReflection->getValue($this);
}

You can do something similar to get the request object. This is a bit of a dirty hack, but it gets the result you want.