The example about accessing contexts from each other triggers:
- the Psalm issue UndefinedInterfaceMethod
- the PHPStorm issue "Potentially polymorphic call. The code may be inoperable depending on the actual class instance passed as the argument"
Indeed, the method getContext() is not necessarily present in every possible Environment interface implementation since it is not declared in this interface. Actually it is declared in InitializedContextEnvironment only.
The piece of code:
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
class FeatureContext implements Context
{
/** @var \Behat\MinkExtension\Context\MinkContext */
private $minkContext;
/** @BeforeScenario */
public function gatherContexts(BeforeScenarioScope $scope)
{
$environment = $scope->getEnvironment();
$this->minkContext = $environment->getContext('Behat\MinkExtension\Context\MinkContext');
}
}