paulgibbs / behat-wordpress-extension

WordHat: Behat for WordPress
https://wordhat.info
GNU General Public License v3.0
106 stars 21 forks source link

Do not work inside a docker container due to wp-cli being executed as root #216

Closed andergmartins closed 5 years ago

andergmartins commented 6 years ago

Expected behaviour

I expect to run the command:

vendor/bin/behat --init

and behat is initialized without any error message.

Current behaviour

When I run the above command, it returns:

Error: YIKES! It looks like you're running this as root. You probably meant to run this as the user that >your WordPress install exists under.

If you REALLY mean to run this as root, we won't stop you, but just bear in mind that any code on this >site will then have full control of your server, making it quite DANGEROUS.

If you'd like to continue as root, please run this again, adding this flag: --allow-root

If you'd like to run it as the user that this site is under, you can run the following to become the >respective user:

sudo -u USER -i -- wp

In WpcliDriver.php line 141:

WP-CLI driver failure in method bootstrap():

(1)

Possible solution

Wp-cli has an option for running as root: --allow-root. Maybe we could detect if we are inside a container or give an option to run: wp as an alias ofwp --allow-root?

Steps to reproduce

  1. Download docker-files.zip
  2. Unzip the files inside a folder called: "wordpress_dev"
  3. Enter the folder: cd wordpress_dev
  4. Start the docker container running: docker-compose up -d
  5. Run bash inside the container: docker run -it wordpress_dev_www_1 bash
  6. Create a new folder simulating the plugin you are working: mkdir wp-content/plugins/myplugin
  7. Enter the folder: cd wp-content/plugins/myplugin
  8. Create a basic plugin file (for the sake of this test I think it can be a blank file callled muplugin.php`)
  9. Run composer require --dev paulgibbs/behat-wordpress-extension behat/mink-goutte-driver behat/mink-selenium2-driver
  10. Try to run initialize behat: vendor/bin/behat --init

After running these steps you should be able to see the error message.

Context

I'm trying to use behat-wordpress-extension for the first time while I developping a WordPress plugin.

Your environment

rvodden commented 6 years ago

I've not tested this (will try it this evening) but you might be able to pass a command line option to wpcli through the configuration item in behat.yml by setting wpcli.binary to (for example) wp --allow-root. As I say, I've not tested that.

paulgibbs commented 6 years ago

you might be able to pass a command line option to wpcli through the configuration item in behat.yml by setting wpcli.binary

Yes, that is possible (see the table on https://wordhat.info/configuration/settings.html) but I don't know if --allow-root is going to work for sure. I can't recall with certainty if we pass any other arguments via WordHat that needs to be in the first position on the command line or not.

paulgibbs commented 6 years ago

@andergmartins Thank you for the very detailed write-up. I'm hopeful that @rvodden's suggestion above might do it for you - try it and let us know?

We'll consider whether we can or should auto-set this parameter for the WP-CLI driver or not.

paulgibbs commented 5 years ago

Given there is a workaround suggested above that should work, I'm going to close this ticket, as there are other priorities in WordHat's development that I feel are a better use of my own time. Personally, I'm not sure of the benefit to automatically handle running Behat/WP-CLI as root, but I would accept a well-written PR that implements that.

If anyone's game, please re-open this ticket and we can discuss. Thanks all!