Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: Call to a member function open() on null #98

Closed
nietzscheson opened this issue Oct 3, 2017 · 9 comments
Closed

Fatal error: Call to a member function open() on null #98

nietzscheson opened this issue Oct 3, 2017 · 9 comments

Comments

@nietzscheson
Copy link
Contributor

My project works on Vagrant with Docker Engine. I have the follow configurations in behat:

###behat.yml
default:

    extensions:
        Behat\MinkExtension:
            base_url: "http://192.168.33.10/app_test.php/"
#            default_session: chrome
            javascript_session: chrome
            sessions:
                chrome:
                    selenium2:
                        wd_host: "http://192.168.33.10:4444/wd/hub/"
                        browser: chrome
                        capabilities:
                            browserName: chrome
                            browser: chrome
                            version: ""
                            chrome:
                                switches:
                                    - "start-fullscreen"
                                    - "start-maximized"
                                    - "no-sandbox"

        SensioLabs\Behat\PageObjectExtension: ~

### sign_in.feature
@security
Feature: Sign in into Application

    @ui
    Scenario: Search
        Given I am on the login
        When I fill the username with "user@usuario.com"
        And I fill the password with "password"
        When I want a login
        Then I should see "Credenciales no válidas."
class SecurityContext implements Context
{

private $loginPage;

public function __construct(LoginPage $loginPage)
{
  $this->loginPage = $loginPage;
}

/**
 * @Given I am on the login
 */
public function iAmOnTheLogin()
{
   $this->loginPage->open();
}

When I run behat it fails and throws me the error: Fatal error: Call to a member function open() on null (Behat\Testwork\Call\Exception\FatalThrowableError)

@DonCallisto
Copy link
Contributor

Sounds weird: are you sure you're not overriding $this->loginPage somehow? Because if $loginPage in __construct was null, then type-hint should have failed

@nietzscheson
Copy link
Contributor Author

The loginPage:

<?php

namespace Behat\Page\Security;

use SensioLabs\Behat\PageObjectExtension\PageObject\Page;

class LoginPage extends Page
{
  protected $path = 'login';
}

@DonCallisto
Copy link
Contributor

@nietzscheson could you put a var_dump after $this->loginPage = $loginPage; and tell us what you get?

@nietzscheson
Copy link
Contributor Author

It's the result of var_dump($this->loginPage):

class ProxyManagerGeneratedProxy\__PM__\Behat\Page\Security\LoginPage\Generated892a68bed1424ff805ea5e5652e59e48#4143 (10) {private $valueHolder59d3b5d715938297741385 =>
      │   NULLprivate $initializer59d3b5d715c36812164521 =>
      │   class Closure#3957 (3) {public $static =>
      │     array(2) {
      │       'pageObjectClass' =>
      │       string(29) "Behat\Page\Security\LoginPage"
      │       'decoratedFactory' =>
      │       class SensioLabs\Behat\PageObjectExtension\PageObject\Factory\DefaultFactory#3757 (3) {
      │         ...
      │       }
      │     }
      │     public $this =>
      │     class SensioLabs\Behat\PageObjectExtension\PageObject\Factory\LazyFactory#3763 (2) {
      │       private $decoratedFactory =>
      │       class SensioLabs\Behat\PageObjectExtension\PageObject\Factory\DefaultFactory#3757 (3) {
      │         ...
      │       }
      │       private $proxyFactory =>
      │       class ProxyManager\Factory\LazyLoadingValueHolderFactory#3759 (3) {
      │         ...
      │       }
      │     }
      │     public $parameter =>
      │     array(5) {
      │       '&$wrappedObject' =>
      │       string(10) "<required>"
      │       '$proxy' =>
      │       string(10) "<required>"
      │       '$method' =>
      │       string(10) "<required>"
      │       '$parameters' =>
      │       string(10) "<required>"
      │       '&$initializer' =>
      │       string(10) "<required>"
      │     }
      │   }
      │ }

@DonCallisto
Copy link
Contributor

As you can see, LoginPage is injected in the right way. Are you sure that you're not overriding its value elsewhere?

@nietzscheson
Copy link
Contributor Author

I'm not sure. I only have those classes

@nietzscheson
Copy link
Contributor Author

nietzscheson commented Oct 3, 2017

if modify this line:

public function open(array $urlParameters = array())
{
  $url = $this->getUrl($urlParameters);

  $this->getDriver()->visit($url);

  $this->verify($urlParameters);

  return $this;
}

For this, works:

public function open(array $urlParameters = array())
{
  $url = $this->getUrl($urlParameters);

  $this->getSession()->visit($url);

  $this->verify($urlParameters);

  return $this;
}

It's as if I was not able to resolve the driver to handle the session ... with the session directly, everything is fine ...

@nietzscheson
Copy link
Contributor Author

Update the composer with composer update --prefer-stable and works:

  • Old composer:
behat/behat                                     v3.4.1             Scenario-oriented BDD framework for PHP 5.3
behat/gherkin                                   v4.5.1             Gherkin DSL parser for PHP 5.3
behat/mink                                      dev-master 9ea1ceb Browser controller/emulator abstraction for PHP
behat/mink-browserkit-driver                    dev-master 1c9c8ad Symfony2 BrowserKit driver for Mink framework
behat/mink-extension                            v2.2               Mink extension for Behat
behat/mink-selenium2-driver                     dev-master 46404b0 Selenium2 (WebDriver) driver for Mink framework
behat/symfony2-extension                        dev-master 319b56c Symfony2 framework extension for Behat

New Composer:

behat/behat                                     v3.4.1             Scenario-oriented BDD framework for PHP 5.3
behat/gherkin                                   v4.5.1             Gherkin DSL parser for PHP 5.3
behat/mink                                      v1.7.1             Browser controller/emulator abstraction for PHP
behat/mink-browserkit-driver                    v1.3.2             Symfony2 BrowserKit driver for Mink framework
behat/mink-extension                            v2.2               Mink extension for Behat
behat/mink-selenium2-driver                     v1.3.1             Selenium2 (WebDriver) driver for Mink framework
behat/symfony2-extension                        2.1.1              Symfony2 framework extension for Behat

@jakzal
Copy link
Member

jakzal commented Oct 4, 2017

Perhaps it's related to some non-BC changes in mink, like #92.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants