stephenharris / WordPressBehatExtension

WordPress extension for Behat 3
Other
8 stars 5 forks source link

Call to undefined function #16

Closed Simek11 closed 7 years ago

Simek11 commented 7 years ago

I would like to use WordPress functions in my own FeatureContext class and write steps which are not presented in WordPressBehatExtension. Behat returns some issue when I try example from documentation. If my behat.yml file looks like this:

default:
  suites:
    default:
      contexts:
        - FeatureContext
        - \StephenHarris\WordPressBehatExtension\Context\WordPressContext
        - \StephenHarris\WordPressBehatExtension\Context\Plugins\WordPressPluginContext
  extensions:
    StephenHarris\WordPressBehatExtension:
      path: '/var/www/wordpress'
      connection:
        db: "wordpress"
        username: "wordpress"
        password: "wordpress"
      flush_database: false
      mail:
        directory: '/tmp/mail'
    Behat\MinkExtension:
      base_url: "http://192.168.33.10"
      browser_name: chrome
      goutte: ~
      selenium2: ~

and my .feature file looks like this:

Feature: Admin activates plugin
  In order to use the plugin
  As a WordPress user
  I should be able to activate it

  Scenario: Enable the dolly plugin
    Given there are plugins
      | plugin    | status  |
      | hello.php | enabled |
    When I go to "/wp-admin/"
    Then I should see a "#dolly" element

I get error when try to run Behat:

PHP Fatal error: Call to undefined function StephenHarris\WordPressBehatExtension\Context\Plugins\activate_plugin() in /home/vagrant/my-plugin/vendor/stephenharris/wordpress-behat-extension/src/Context/Plugins/WordPressPluginContext.php on line 21

What did I do wrong? I use vccw vagrant and run tests after I ssh into it.

stephenharris commented 7 years ago

Looks like activate_plugin() is being loaded. It's not clear why that's the case, but you may want to check that this line is being reached.

You are missing a Given I have a vanilla WordPress installation step too. That shouldn't cause an undefined function call, but maybe the context is never instantiated if not steps are required of it?

Simek11 commented 7 years ago

Thank you for your response. I've checked if this line is being reached and the answer is yes. The missing given step you've mentioned is the case. If I start my scenario with Given I have a vanilla wordpress installation, I don't get any errors, but if this given step is missing, activate_plugin() function is not being found. I'm not very fond of using it in this way. I thought that if I don't want to install WordPress in every scenario, I can put some empty step into this WordPressContext and call it in every scenario as given step in order to make this class loaded. Unfortunately, it doesn't work. It seems that the installWordPress() method must be called. I don't understand why this class is so important since it has only one method.

stephenharris commented 7 years ago

WordPressBehatExtension resets the database after ever scenario to avoid bleeding between scenarios. I imagine your step is failing because you're actually getting the install screen.

Can I recommend you look at WordHat, which I'm collaborating on. It is similar to WordPressBehatExtension but with a crucial difference, it does not reset the database, and it does not install WordPress - that is, you're expected to insure your WordPress install is set up for testing yourself, and that you reset the database (if that is required). It sounds like that might more readily meet your needs.

Simek11 commented 7 years ago

It seems to be a helpful library. I can't use it, though. My PHP 5.3 environment doesn't meet WordHat's requirements. But I will know what library I should check in the future. Thank you for the recommendation.