Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

HOW TO: Run Behat tests on Travis using a dependency

Description

This document describes how to run Behat tests on Travis when there are multiple dependencies that need to be tied together.

Step 1 - preparing branches

In order to be able to use your branches in other Pull Requests they need to be on ezsystems repository. Otherwise you might encouncer GitHub API limits which will stop the process.

Step 2 - preparing metarepository with dependencies

You need to create a new branch of a metarepository (ezplatform or other) that originates from the version branch you're targeting. It can be created on fork. If you want to run tests using a public package (for example AdminUI) use ezplatform or ezplatform-demo, if your PR is to a private package (for example PageBuilder) use ezplatform-ee or ezplatform-ee-demo.

There you have to specify in composer.json:

  • your branches as dependencies, for example if you need to use mybranch from ezpublish-kernel and you're targetting version 2.5 you need to set: "ezsystems/ezpublish-kernel": "dev-mybranch as 7.5.x-dev",
  • EE repositories have to be added to the repositories section, for example:
"repositories": [
        { "type": "composer", "url": "https://updates.ez.no/ttl" },
        {
            "type": "vcs",
            "url": "https://github.com/ezsystems/ezplatform-form-builder.git"
        },
        {
            "type": "vcs",
            "url": "https://github.com/ezsystems/ezplatform-page-builder.git"
        },
        {
            "type": "vcs",
            "url": "https://github.com/ezsystems/flex-workflow.git"
        },
        {
            "type": "vcs",
            "url": "https://github.com/ezsystems/ezplatform-workflow.git"
        }

    ],

Add only these you'll need. It's worth executing composer update --dry-run and making sure you are getting correct dependencies.

Step 3 - making Travis use your metarepository

Now you need to set up Travis in the branch where you want to run the tests to use your metarepository. There are two things to set:

  1. Metarepository URL in .travis.yml

AdminUI example: https://github.com/ezsystems/ezplatform-admin-ui/blob/master/.travis.yml#L23

env:
  global:
    # For acceptance tests
    - EZPLATFORM_REPO="https://github.com/ezsystems/ezplatform.git"

If your metarepository has been created on the fork change the value to adjust for that.

  1. Metarepository branch in composer.json:

AdminUI example: https://github.com/ezsystems/ezplatform-admin-ui/blob/master/composer.json

    "extra": {
        "_ezplatform_branch_for_behat_tests": "master",
        "branch-alias": {
            "dev-tmp_ci_branch": "2.0.x-dev",
            "dev-master": "2.0.x-dev"
        }
    }

Change the value of _ezplatform_branch_for_behat_tests to the name of your branch (do not prefix it with dev-, just name of the branch).

Example: assuming I have a "mymetarepobranch" on http://github.com/mnocon/ezplatform.git repository (fork of ezplatform) I'd set the values to:

(.travis.yml)
env:
  global:
    # For acceptance tests
    - EZPLATFORM_REPO="https://github.com/mnocon/ezplatform.git"
(composer.json)
    "extra": {
        "_ezplatform_branch_for_behat_tests": "mymetarepobranch",
        "branch-alias": {
            "dev-tmp_ci_branch": "2.0.x-dev",
            "dev-master": "2.0.x-dev"
        }
    }

Step 4 - Running correct test suite

When a PR is created Travis runs the usual test suite for given repository. If you would like to modify it then you have to change the Behat profile and suite accordingly.

Example: Travis config from Page Builder (https://github.com/ezsystems/ezplatform-page-builder/blob/master/.travis.yml#L38)

    # PR-only jobs
    - if: type == pull_request
      name: "PageBuilder UI Tests"
      env: BEHAT_OPTS="--profile=pageBuilder --suite=pageBuilder"

If you would like to run ALL Behat tests on a PR to PageBuilder, change it to:

    # PR-only jobs
    - if: type == pull_request
      name: "PageBuilder UI Tests"
      env: BEHAT_OPTS="--profile=regression --suite=regression"

Step 5 - Commiting changes

Commit these changes and mark your Pull Request as [DON'T MERGE] to make sure that they aren't merged by accident. The Pull Request where the changes are commited can be:

  1. a brand new PR, when the target repository is not among the repositories where the changes are done
  2. an existing one (with DEV changes) when the reporitory is among changed dependencies

Step 6 - Cleanup

  • Remove any branches that have been created on ezsystems and are no longer needed.
  • (Optional) if the build is green you can post a comment with the build link as a proof 🙂
  • If the PR has been created just for running tests you can simply close it.
  • If the PR contains other code: remove the temporary commit from step 5 before it is merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment