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

[Support - with Solution] Best place to set BEHAT_PARAMS #93

Closed
subhojit777 opened this issue Sep 17, 2016 · 5 comments
Closed

[Support - with Solution] Best place to set BEHAT_PARAMS #93

subhojit777 opened this issue Sep 17, 2016 · 5 comments

Comments

@subhojit777
Copy link

Inside before_script:

before_script:
  - drupal-ti before_script
  - drupal-ti --include drupal_ti/before/before_script.sh
  - drupal-ti --include drupal_ti/before/runners/behat/before_script.sh

And I have a file like this drupal_ti/before/runners/behat/before_script.sh:

#!/bin/bash

# Add an optional statement to see that this is running in Travis CI.
echo "running drupal_ti/before/runners/behat/before_script.sh"

set -e $DRUPAL_TI_DEBUG

export BEHAT_PARAMS='{"extensions":{"Behat\\MinkExtension":{"base_url":"DRUPAL_TI_WEBSERVER_URL:DRUPAL_TI_WEBSERVER_PORT/"},"Drupal\\DrupalExtension":{"drush":{"root":"DRUPAL_TI_DRUPAL_DIR"},"drupal":{"drupal_root":"DRUPAL_TI_DRUPAL_DIR"}}}}'
BEHAT_PARAMS=`echo $BEHAT_PARAMS | sed -e "s#DRUPAL_TI_WEBSERVER_URL#$DRUPAL_TI_WEBSERVER_URL#" -e "s#DRUPAL_TI_WEBSERVER_PORT#$DRUPAL_TI_WEBSERVER_PORT#" -e "s#DRUPAL_TI_DRUPAL_DIR#$DRUPAL_TI_DRUPAL_DIR#" -e "s#DRUPAL_TI_DRUPAL_DIR#$DRUPAL_TI_DRUPAL_DIR#"`
export BEHAT_PARAMS
echo $BEHAT_PARAMS

But it seems the BEHAT_PARAMS is not considered when the tests are run. And it fails with error:

[InvalidArgumentException]          
Driver "drupal" is not registered.

Any idea why this is happening?

As a workaround I am setting BEHAT_PARAMS under before_script like this:

  # Setting Behat environment
  - DRUPAL_DIR="$TRAVIS_BUILD_DIR/../$DRUPAL_TI_ENVIRONMENT/drupal"
  - BEHAT_PARAMS='{"extensions":{"Behat\\MinkExtension":{"base_url":"DRUPAL_TI_WEBSERVER_URL:DRUPAL_TI_WEBSERVER_PORT/"},"Drupal\\DrupalExtension":{"drush":{"root":"DRUPAL_DIR"},"drupal":{"drupal_root":"DRUPAL_DIR"}}}}'
  - BEHAT_PARAMS=`echo $BEHAT_PARAMS | sed -e s#DRUPAL_TI_WEBSERVER_URL#$DRUPAL_TI_WEBSERVER_URL# -e s#DRUPAL_TI_WEBSERVER_PORT#$DRUPAL_TI_WEBSERVER_PORT# -e s#DRUPAL_DIR#$DRUPAL_DIR# -e s#DRUPAL_DIR#$DRUPAL_DIR#`
  - export BEHAT_PARAMS
@LionsAd
Copy link
Owner

LionsAd commented Sep 18, 2016

There is several things mixed here:

a) The easiest solution likely is just to source your script with parameters:

- . behat-params.sh

or

- source ./behat-params.sh

That will ensure that environment variables are exported correctly.

b) You can set all those behat parameters already in a custom behat.yml.dist file including placeholders for all environment variables, see the test behat test in the drupal-7 / drupal-8 test directories:

https://github.com/LionsAd/drupal_ti/blob/master/tests/drupal-7/drupal_ti_test/tests/behat/behat.yml.dist

c) When you want to use the before or after functionality you can run in the same environment as the runner you want to extend, there is no need to --include that:

- DRUPAL_TI_SCRIPT_DIR_BEFORE="./drupal_ti/before"

You need to uncomment that in your .travis.yml, then it will automatically find e.g. drupal_ti/before/runners/behat/script.sh and you can set environment variables there.

Hope that helps! :)

@LionsAd LionsAd changed the title Best place to set BEHAT_PARAMS [Support - with Solution] Best place to set BEHAT_PARAMS Sep 18, 2016
@subhojit777
Copy link
Author

subhojit777 commented Sep 18, 2016

Thanks! I missed the behat.yml.dist in the README. That really helped and it is working.

BTW I have another confusion regarding the "before" script. You have asked to uncomment this:

- DRUPAL_TI_SCRIPT_DIR_BEFORE="./drupal_ti/before"

But it seems like it is not considering the scripts. Where do I have to put this drupal_ti directory. Currently it is placed just under my module's directory like this:

mymodule
  - tests/
  - drupal_ti/
  - mymodule.info
  - mymodule.module

I have also tried placing drupal_ti under tests directory, and changed DRUPAL_TI_SCRIPT_DIR_BEFORE this to:

- DRUPAL_TI_SCRIPT_DIR_BEFORE="./tests/drupal_ti/before"

But it is still not working. Only option to make it work is "including" it under before_script. Am I doing something wrong?

@subhojit777
Copy link
Author

Inside before_script.sh:

#!/bin/bash

# Add an optional statement to see that this is running in Travis CI.
echo "running drupal_ti/before/before_script.sh"

set -e $DRUPAL_TI_DEBUG

# Install list.js library.
cd "$DRUPAL_TI_DRUPAL_DIR/$DRUPAL_TI_LIBRARIES_DIR"
wget "https://github.com/javve/list.js/archive/v$DRUPAL_TI_LISTJS_VERSION.tar.gz"
tar -xzf "v$DRUPAL_TI_LISTJS_VERSION.tar.gz"
mv "list.js-$DRUPAL_TI_LISTJS_VERSION" "listjs"

# Enable required modules.
drush en -y "features"
drush en -y "views"
drush en -y "views_ui"

@szeidler
Copy link

Thanks for the awesome project.

I'm struggling with the same issue as @subhojit777. I cannot make the autodiscovery work when using DRUPAL_TI_SCRIPT_DIR_BEFORE.

I defined - DRUPAL_TI_SCRIPT_DIR_BEFORE="./tests/drupal_ti/before"
and have the script placed in tests/drupal_ti/before/runners/behat/before_script.sh. But it's not taken into account.

Do you have any suggestions?

@subhojit777
Copy link
Author

@szeidler I did like this https://github.com/subhojit777/listjs/blob/7.x-1.x/tests/behat.yml#L39 and asked Travis to run the specific profile like this https://github.com/subhojit777/listjs/blob/7.x-1.x/.travis.yml#L51

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