Skip to content

$environment->getContext triggers the Psalm issue UndefinedInterfaceMethod #141

Description

@Kwadz

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');
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions