Open Kwadz opened 3 years ago
This might be solved by improving types based on the different scopes. The BeforeScenarioScope
is guaranteed to get an environment implementing Behat\Behat\Context\Environment\ContextEnvironment
, and I think even an InitializedContextEnvironment for that one (for BeforeSuite
, that might not be an InitializedContextEnvironment, but it would still be a ContextEnvironment)
getContext
public method is available only in specific ContextEnvironment
implementations as it's not listed on the interface. FriendsOfBehat/SymfonyExtension
implements that interface as well and provides getContext
method additionally, but there's still no guarantee any other implementation will have that method.
The example about accessing contexts from each other triggers:
Indeed, the method
getContext()
is not necessarily present in every possibleEnvironment
interface implementation since it is not declared in this interface. Actually it is declared inInitializedContextEnvironment
only.The piece of code: